@@ -11,6 +11,8 @@ main :: IO ()
11
11
main = Tasty. defaultMain $ Tasty. testGroup " tests"
12
12
[ test_backslashWrapped
13
13
, test_backslashWrapped_roundTrip
14
+ , test_backslash
15
+ , test_backslash_roundTrip
14
16
]
15
17
16
18
run :: Tasty. TestTree -> IO ()
@@ -51,49 +53,73 @@ test_backslashWrapped = Tasty.testGroup "backslashWrapped"
51
53
-- it goes from reasonable input to the right haskell, and round trip will
52
54
-- ensure it goes back to the original state.
53
55
test_backslashWrapped_roundTrip :: Tasty. TestTree
54
- test_backslashWrapped_roundTrip = Tasty. testGroup " roundTrip"
55
- [ backslashWrapped [" one line" ]
56
- , backslashWrapped [" two" , " lines" ]
57
- , backslashWrapped
56
+ test_backslashWrapped_roundTrip = Tasty. testGroup " backslashWrapped_roundTrip" $
57
+ map trip
58
+ [ [" one line" ]
59
+ , [" two" , " lines" ]
60
+ ,
58
61
[ " with an"
59
62
, " explicit"
60
63
, " "
61
64
, " newline"
62
65
]
63
66
]
64
67
where
65
- backslashWrapped = trip
68
+ trip = roundTrip
66
69
StringLiteral. addBackslashWrapped StringLiteral. removeBackslashWrapped
67
70
68
- trip :: (Stack. HasCallStack , Show a , Eq a ) => (a -> b ) -> (b -> a ) -> a
71
+ test_backslash :: Tasty. TestTree
72
+ test_backslash = Tasty. testGroup " backslash"
73
+ [ [" one line" ] ==> [" \" one line\\ n\" " ]
74
+ , [" two" , " lines" ] ==> [" \" two\\ n\\ " , " \\ lines\\ n\" " ]
75
+ ,
76
+ [ " with an"
77
+ , " explicit"
78
+ , " "
79
+ , " newline"
80
+ ] ==>
81
+ [ " \" with an\\ n\\ "
82
+ , " \\ explicit\\ n\\ "
83
+ , " \\\\ n\\ "
84
+ , " \\ newline\\ n\" "
85
+ ]
86
+ ,
87
+ [ " with"
88
+ , " explicit"
89
+ , " indent"
90
+ ] ==>
91
+ [ " \" with\\ n\\ "
92
+ , " \\ explicit\\ n\\ "
93
+ , " \\ indent\\ n\" "
94
+ ]
95
+ ]
96
+ where
97
+ (==>) :: Stack. HasCallStack => [Text ] -> [Text ] -> Tasty. TestTree
98
+ (==>) = test StringLiteral. addBackslash
99
+
100
+ test_backslash_roundTrip :: Tasty. TestTree
101
+ test_backslash_roundTrip = Tasty. testGroup " backslash_roundTrip" $ map trip
102
+ [ [" one line" ]
103
+ , [" two" , " lines" ]
104
+ ,
105
+ [ " with an"
106
+ , " explicit"
107
+ , " "
108
+ , " newline"
109
+ ]
110
+ ,
111
+ [ " with"
112
+ , " explicit"
113
+ , " indent"
114
+ ]
115
+ ]
116
+ where
117
+ trip = roundTrip StringLiteral. addBackslash StringLiteral. removeBackslash
118
+
119
+ roundTrip :: (Stack. HasCallStack , Show a , Eq a ) => (a -> b ) -> (b -> a ) -> a
69
120
-> Tasty. TestTree
70
- trip f g x = HUnit. testCase (take 70 $ show x) $ g (f x) HUnit. @?= x
121
+ roundTrip f g x = HUnit. testCase (take 70 $ show x) $ g (f x) HUnit. @?= x
71
122
72
123
test :: (Stack. HasCallStack , Show a , Eq b , Show b ) => (a -> b ) -> a -> b
73
124
-> Tasty. TestTree
74
125
test f x expected = HUnit. testCase (take 70 $ show x) $ f x HUnit. @?= expected
75
-
76
- -- _test_addBackslash = Text.IO.putStr $ Text.unlines $ addBackslash
77
- -- [ " foo"
78
- -- , ""
79
- -- , " bar"
80
- -- ]
81
-
82
- -- test1 = HUnit.testCase "test1"
83
- -- [ [1, 2, 3] `compare` [1,2] === GT
84
- -- , [1, 2, 3] `compare` [1,2,2] === LT
85
- -- ]
86
-
87
- -- unitTests :: Tasty.TestTree
88
- -- unitTests = Tasty.testGroup "Unit tests"
89
- -- [ HUnit.testCase "blah" $
90
- -- [1, 2, 3] `compare` [1,2] @?= GT
91
- --
92
- -- -- the following test does not hold
93
- -- , HUnit.testCase "List comparison (same length)" $
94
- -- [1, 2, 3] `compare` [1,2,2] @?= LT
95
- -- ]
96
-
97
-
98
- (===) :: (Eq a , Show a ) => a -> a -> HUnit. Assertion
99
- (===) = (HUnit. @?=)
0 commit comments