Skip to content

Commit

Permalink
Test gEncodeJson with a more complex data structure
Browse files Browse the repository at this point in the history
  • Loading branch information
zudov committed Aug 25, 2015
1 parent 3c1edd5 commit 8fa59a6
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions test/Test/Main.purs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ prop_decode_then_encode (TestJson json) =
Right json == (decoded >>= (encodeJson >>> pure))


encodeDecodeCheck = do
encodeDecodeCheck = do
log "Showing small sample of JSON"
showSample (genJson 10)

Expand All @@ -82,7 +82,7 @@ prop_assoc_builder_str :: Tuple String String -> Boolean
prop_assoc_builder_str (Tuple key str) =
case (key := str) of
Tuple k json ->
(key == k) && (decodeJson json == Right str)
(key == k) && (decodeJson json == Right str)

newtype Obj = Obj Json
unObj :: Obj -> Json
Expand Down Expand Up @@ -111,7 +111,7 @@ prop_get_jobject_field (Obj obj) =
in foldl (\ok key -> ok && (isJust $ M.lookup key obj)) true keys

assert_maybe_msg :: Boolean
assert_maybe_msg =
assert_maybe_msg =
(isLeft (Nothing ?>>= "Nothing is Left"))
&&
((Just 2 ?>>= "Nothing is left") == Right 2)
Expand All @@ -133,8 +133,14 @@ newtype MyRecord = MyRecord { foo :: String, bar :: Int}
derive instance genericMyRecord :: Generic MyRecord

data User = Anonymous
| Registered String Int

| Guest String
| Registered { name :: String
, age :: Int
, balance :: Number
, banned :: Boolean
, tweets :: Array String
, followers :: Array User
}
derive instance genericUser :: Generic User

prop_iso_generic :: GenericValue -> Boolean
Expand All @@ -160,7 +166,21 @@ genericsCheck = do
print $ gEncodeJson $ MyRecord { foo: "foo", bar: 2}
print $ gEncodeJson "foo"
print $ gEncodeJson Anonymous
print $ gEncodeJson $ Registered "zudov" 5
print $ gEncodeJson $ Guest "guest's handle"
print $ gEncodeJson $ Registered { name: "user1"
, age: 5
, balance: 26.6
, banned: false
, tweets: ["Hello", "What's up"]
, followers: [ Anonymous
, Guest "someGuest"
, Registered { name: "user2"
, age: 6
, balance: 32.1
, banned: false
, tweets: ["Hi"]
, followers: []
}]}


main = do
Expand Down

0 comments on commit 8fa59a6

Please sign in to comment.