@@ -45,12 +45,12 @@ foldTest = do
45
45
46
46
foldFn :: Json -> String
47
47
foldFn = caseJson
48
- (const " null" )
49
- (const " boolean" )
50
- (const " number" )
51
- (const " string" )
52
- (const " array" )
53
- (const " object" )
48
+ (const " null" )
49
+ (const " boolean" )
50
+ (const " number" )
51
+ (const " string" )
52
+ (const " array" )
53
+ (const " object" )
54
54
55
55
cases :: Array Json
56
56
cases =
@@ -64,44 +64,63 @@ cases =
64
64
65
65
foldXXX :: Effect Unit
66
66
foldXXX = do
67
- assert ((caseJsonNull " not null" (const " null" ) <$> cases) ==
68
- [" null" , " not null" , " not null" , " not null" , " not null" , " not null" ] <?>
69
- " Error in caseJsonNull" )
70
- assert ((caseJsonBoolean " not boolean" (const " boolean" ) <$> cases) ==
71
- [" not boolean" , " boolean" , " not boolean" , " not boolean" , " not boolean" , " not boolean" ] <?>
72
- " Error in caseJsonBoolean" )
73
- assert ((caseJsonNumber " not number" (const " number" ) <$> cases) ==
74
- [" not number" , " not number" , " number" , " not number" , " not number" , " not number" ] <?>
75
- " Error in caseJsonNumber" )
76
-
77
- assert ((caseJsonString " not string" (const " string" ) <$> cases) ==
78
- [" not string" , " not string" , " not string" , " string" , " not string" , " not string" ] <?>
79
- " Error in caseJsonString" )
80
-
81
- assert ((caseJsonArray " not array" (const " array" ) <$> cases) ==
82
- [" not array" , " not array" , " not array" , " not array" , " array" , " not array" ] <?>
83
- " Error in caseJsonArray" )
84
- assert ((caseJsonObject " not object" (const " object" ) <$> cases) ==
85
- [" not object" , " not object" , " not object" , " not object" , " not object" , " object" ] <?>
86
- " Error in caseJsonObject" )
87
-
67
+ assert
68
+ ( (caseJsonNull " not null" (const " null" ) <$> cases) ==
69
+ [ " null" , " not null" , " not null" , " not null" , " not null" , " not null" ] <?>
70
+ " Error in caseJsonNull"
71
+ )
72
+ assert
73
+ ( (caseJsonBoolean " not boolean" (const " boolean" ) <$> cases) ==
74
+ [ " not boolean" , " boolean" , " not boolean" , " not boolean" , " not boolean" , " not boolean" ] <?>
75
+ " Error in caseJsonBoolean"
76
+ )
77
+ assert
78
+ ( (caseJsonNumber " not number" (const " number" ) <$> cases) ==
79
+ [ " not number" , " not number" , " number" , " not number" , " not number" , " not number" ] <?>
80
+ " Error in caseJsonNumber"
81
+ )
82
+
83
+ assert
84
+ ( (caseJsonString " not string" (const " string" ) <$> cases) ==
85
+ [ " not string" , " not string" , " not string" , " string" , " not string" , " not string" ] <?>
86
+ " Error in caseJsonString"
87
+ )
88
+
89
+ assert
90
+ ( (caseJsonArray " not array" (const " array" ) <$> cases) ==
91
+ [ " not array" , " not array" , " not array" , " not array" , " array" , " not array" ] <?>
92
+ " Error in caseJsonArray"
93
+ )
94
+ assert
95
+ ( (caseJsonObject " not object" (const " object" ) <$> cases) ==
96
+ [ " not object" , " not object" , " not object" , " not object" , " not object" , " object" ] <?>
97
+ " Error in caseJsonObject"
98
+ )
88
99
89
100
fromTest :: Effect Unit
90
101
fromTest = do
91
102
assert ((caseJsonNull false (const true ) jsonNull) <?> " Error in fromNull" )
92
103
quickCheck (\bool -> caseJsonBoolean Nothing Just (fromBoolean bool) == Just bool <?> " Error in fromBoolean" )
93
104
quickCheck (\num -> caseJsonNumber Nothing Just (fromNumber num) == Just num <?> " Error in fromNumber" )
94
105
quickCheck (\str -> caseJsonString Nothing Just (fromString str) == Just str <?> " Error in fromString" )
95
- quickCheck (\num ->
96
- let arr :: Array Json
97
- arr = A .singleton (fromNumber num)
98
- in (caseJsonArray Nothing Just (fromArray arr) == Just arr)
99
- <?> " Error in fromArray" )
100
- quickCheck (\(Tuple str num) ->
101
- let sm :: Obj.Object Json
102
- sm = Obj .singleton str (fromNumber num)
103
- in (caseJsonObject Nothing Just (fromObject sm) == Just sm)
104
- <?> " Error in fromObject" )
106
+ quickCheck
107
+ ( \num ->
108
+ let
109
+ arr :: Array Json
110
+ arr = A .singleton (fromNumber num)
111
+ in
112
+ (caseJsonArray Nothing Just (fromArray arr) == Just arr)
113
+ <?> " Error in fromArray"
114
+ )
115
+ quickCheck
116
+ ( \(Tuple str num) ->
117
+ let
118
+ sm :: Obj.Object Json
119
+ sm = Obj .singleton str (fromNumber num)
120
+ in
121
+ (caseJsonObject Nothing Just (fromObject sm) == Just sm)
122
+ <?> " Error in fromObject"
123
+ )
105
124
106
125
toTest :: Effect Unit
107
126
toTest = do
@@ -114,10 +133,11 @@ toTest = do
114
133
where
115
134
assertion :: forall a . (Eq a ) => (Json -> Maybe a ) -> Json -> String -> Result
116
135
assertion fn j msg =
117
- let forCases = A .catMaybes (fn <$> cases)
118
- exact = A .singleton $ unsafePartial fromJust $ fn j
119
- in forCases == exact <?> msg
120
-
136
+ let
137
+ forCases = A .catMaybes (fn <$> cases)
138
+ exact = A .singleton $ unsafePartial fromJust $ fn j
139
+ in
140
+ forCases == exact <?> msg
121
141
122
142
parserTest :: Effect Unit
123
143
parserTest = do
@@ -128,7 +148,7 @@ parserTest = do
128
148
roundtripTest = do
129
149
json <- Gen .resize (const 5 ) genJson
130
150
let parsed = jsonParser (stringify json)
131
- pure $ parsed == Right json <?> show (stringify <$> parsed) <> " /= " <> stringify json
151
+ pure $ parsed == Right json <?> show (stringify <$> parsed) <> " /= " <> stringify json
132
152
133
153
assert :: forall prop . Testable prop => prop -> Effect Unit
134
154
assert = quickCheck' 1
0 commit comments