@@ -20,7 +20,6 @@ import Effect.Console (log)
2020import Effect.Exception (error , throw )
2121import Test.QuickCheck (class Arbitrary , arbitrary , quickCheck )
2222import Test.QuickCheck.Arbitrary (genericArbitrary )
23- import Test.QuickCheck.Gen (Gen )
2423import Test.Util (propCodec )
2524
2625-- ------------------------------------------------------------------------------
@@ -51,7 +50,11 @@ codecSample encoding = sumWith encoding "Sample"
5150data SampleFlat
5251 = FlatFoo
5352 | FlatBar { errors ∷ Int }
54- | FlatBaz { active ∷ Boolean , name ∷ String , count ∷ Int }
53+ | FlatBaz
54+ { active ∷ Boolean
55+ , name ∷ String
56+ , pos ∷ { x ∷ Int , y ∷ Int }
57+ }
5558
5659derive instance Generic SampleFlat _
5760derive instance Eq SampleFlat
@@ -66,7 +69,14 @@ codecSampleFlat ∷ JsonCodec SampleFlat
6669codecSampleFlat = sumFlat @" tag" " Sample"
6770 { " FlatFoo" : unit
6871 , " FlatBar" : CR .record { errors: C .int }
69- , " FlatBaz" : CR .record { active: C .boolean, name: C .string, count: C .int }
72+ , " FlatBaz" : CR .record
73+ { active: C .boolean
74+ , name: C .string
75+ , pos: CR .object " Pos"
76+ { x: C .int
77+ , y: C .int
78+ }
79+ }
7080 }
7181
7282-- ------------------------------------------------------------------------------
@@ -360,13 +370,16 @@ main = do
360370 , " }"
361371 ]
362372
363- check codecSampleFlat (FlatBaz { active: true , name: " hello" , count: 42 })
373+ check codecSampleFlat (FlatBaz { active: true , name: " hello" , pos: { x: 42 , y: 42 } })
364374 $ Str .joinWith " \n "
365375 [ " {"
366376 , " \" tag\" : \" FlatBaz\" ,"
367377 , " \" active\" : true,"
368- , " \" count\" : 42,"
369- , " \" name\" : \" hello\" "
378+ , " \" name\" : \" hello\" ,"
379+ , " \" pos\" : {"
380+ , " \" x\" : 42,"
381+ , " \" y\" : 42"
382+ , " }"
370383 , " }"
371384 ]
372385
0 commit comments