@@ -45,12 +45,12 @@ foldTest = do
4545
4646foldFn :: Json -> String
4747foldFn = 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" )
5454
5555cases :: Array Json
5656cases =
@@ -64,44 +64,63 @@ cases =
6464
6565foldXXX :: Effect Unit
6666foldXXX = 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+ )
8899
89100fromTest :: Effect Unit
90101fromTest = do
91102 assert ((caseJsonNull false (const true ) jsonNull) <?> " Error in fromNull" )
92103 quickCheck (\bool -> caseJsonBoolean Nothing Just (fromBoolean bool) == Just bool <?> " Error in fromBoolean" )
93104 quickCheck (\num -> caseJsonNumber Nothing Just (fromNumber num) == Just num <?> " Error in fromNumber" )
94105 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+ )
105124
106125toTest :: Effect Unit
107126toTest = do
@@ -114,10 +133,11 @@ toTest = do
114133 where
115134 assertion :: forall a . (Eq a ) => (Json -> Maybe a ) -> Json -> String -> Result
116135 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
121141
122142parserTest :: Effect Unit
123143parserTest = do
@@ -128,7 +148,7 @@ parserTest = do
128148 roundtripTest = do
129149 json <- Gen .resize (const 5 ) genJson
130150 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
132152
133153assert :: forall prop . Testable prop => prop -> Effect Unit
134154assert = quickCheck' 1
0 commit comments