1
+ {-# LANGUAGE CPP #-}
1
2
{-# OPTIONS_GHC -fno-warn-orphans #-}
2
3
module TestSuite.JSON (
3
4
prop_roundtrip_canonical ,
@@ -21,26 +22,30 @@ import Text.JSON.Canonical
21
22
import Data.Aeson (Value (.. ), eitherDecode )
22
23
import Data.String (fromString )
23
24
import qualified Data.Vector as V
25
+ #if MIN_VERSION_aeson(2,0,0)
26
+ import qualified Data.Aeson.KeyMap as KM
27
+ #else
24
28
import qualified Data.HashMap.Strict as HM
29
+ #endif
25
30
26
31
-- text
27
32
import qualified Data.Text as Text
28
33
29
34
prop_aeson_canonical, prop_roundtrip_canonical, prop_roundtrip_pretty, prop_canonical_pretty
30
- :: JSValue -> Bool
35
+ :: JSValue -> Property
31
36
32
37
prop_roundtrip_canonical jsval =
33
- parseCanonicalJSON (renderCanonicalJSON jsval) == Right (canonicalise jsval)
38
+ parseCanonicalJSON (renderCanonicalJSON jsval) === Right (canonicalise jsval)
34
39
35
40
prop_roundtrip_pretty jsval =
36
- parseCanonicalJSON (BS. pack (prettyCanonicalJSON jsval)) == Right jsval
41
+ parseCanonicalJSON (BS. pack (prettyCanonicalJSON jsval)) === Right jsval
37
42
38
43
prop_canonical_pretty jsval =
39
- parseCanonicalJSON (renderCanonicalJSON jsval) ==
44
+ parseCanonicalJSON (renderCanonicalJSON jsval) ===
40
45
fmap canonicalise (parseCanonicalJSON (BS. pack (prettyCanonicalJSON jsval)))
41
46
42
47
prop_aeson_canonical jsval =
43
- eitherDecode (renderCanonicalJSON jsval) == Right (toAeson (canonicalise jsval))
48
+ eitherDecode (renderCanonicalJSON jsval) === Right (toAeson (canonicalise jsval))
44
49
45
50
canonicalise :: JSValue -> JSValue
46
51
canonicalise v@ JSNull = v
@@ -84,7 +89,11 @@ toAeson (JSBool b) = Bool b
84
89
toAeson (JSNum n) = Number (fromIntegral n)
85
90
toAeson (JSString s) = String (fromString s)
86
91
toAeson (JSArray xs) = Array $ V. fromList [ toAeson x | x <- xs ]
92
+ #if MIN_VERSION_aeson(2,0,0)
93
+ toAeson (JSObject xs) = Object $ KM. fromList [ (fromString k, toAeson v) | (k, v) <- xs ]
94
+ #else
87
95
toAeson (JSObject xs) = Object $ HM. fromList [ (fromString k, toAeson v) | (k, v) <- xs ]
96
+ #endif
88
97
89
98
instance Arbitrary Int54 where
90
99
arbitrary = fromIntegral <$>
0 commit comments