@@ -50,6 +50,8 @@ tests = testGroup "unit" [
50 , testCase "bad" $ utcTimeBad
50 , testCase "bad" $ utcTimeBad
52 , testGroup ".:, .:?, .:!" $ fmap (testCase "-") dotColonMark
52 , testGroup ".:, .:?, .:!" $ fmap (testCase "-") dotColonMark
53+ , testGroup "To JSON representation" $ fmap (testCase "-") jsonEncoding
54+ , testGroup "From JSON representation" $ fmap (testCase "-") jsonDecoding
55roundTripCamel :: String -> Assertion
57roundTripCamel :: String -> Assertion
@@ -195,6 +197,26 @@ dotColonMark = [
195 ex2 = "{\"value\": 42 }"
197 ex2 = "{\"value\": 42 }"
196 ex3 = "{\"value\": null }"
198 ex3 = "{\"value\": null }"
200+------------------------------------------------------------------------------
201+-- These tests assert that the JSON serialization doesn't change by accident.
202+-----------------------------------------------------------------------------
204+jsonEncoding :: [Assertion]
206+ assertEqual "Either Left" "{\"Left\":1}" $ encode (Left 1 :: Either Int Int)
207+ , assertEqual "Either Right" "{\"Right\":1}" $ encode (Right 1 :: Either Int Int)
208+ , assertEqual "Nothing" "null" $ encode (Nothing :: Maybe Int)
209+ , assertEqual "Just" "1" $ encode (Just 1 :: Maybe Int)
210+ , assertEqual "Just Nothing" "null" $ encode (Just Nothing :: Maybe (Maybe Int))
211+ , assertEqual "Tuple" "[1,2]" $ encode ((1, 2) :: (Int, Int))
214+jsonDecoding :: [Assertion]
216+ assertEqual "Nothing" (Nothing :: Maybe Int) (decode "null")
217+ , assertEqual "Just" (Just 1 :: Maybe Int) (decode "1")
218+ , assertEqual "Just Nothing" (Just Nothing :: Maybe (Maybe Int)) (decode "null")
199------------------------------------------------------------------------------
221------------------------------------------------------------------------------
200-- Comparison between bytestring and text encoders
222-- Comparison between bytestring and text encoders