@@ -50,6 +50,8 @@ tests = testGroup "unit" [
5050 , testCase "bad" $ utcTimeBad
5151 ]
5252 , testGroup ".:, .:?, .:!" $ fmap (testCase "-") dotColonMark
53+ , testGroup "To JSON representation" $ fmap (testCase "-") jsonEncoding
54+ , testGroup "From JSON representation" $ fmap (testCase "-") jsonDecoding
5355 ]
5456
5557roundTripCamel :: String -> Assertion
@@ -195,6 +197,26 @@ dotColonMark = [
195197 ex2 = "{\"value\": 42 }"
196198 ex3 = "{\"value\": null }"
197199
200+------------------------------------------------------------------------------
201+-- These tests assert that the JSON serialization doesn't change by accident.
202+-----------------------------------------------------------------------------
203+
204+jsonEncoding :: [Assertion]
205+jsonEncoding = [
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))
212+ ]
213+
214+jsonDecoding :: [Assertion]
215+jsonDecoding = [
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")
219+ ]
198220
199221------------------------------------------------------------------------------
200222-- Comparison between bytestring and text encoders