Skip to content

Commit f45ae75

Browse files
BodigrimMikolaj
authored andcommitted
Allow aeson-2.0
1 parent cf8f1da commit f45ae75

File tree

2 files changed

+16
-7
lines changed

2 files changed

+16
-7
lines changed

hackage-security/hackage-security.cabal

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,11 +260,11 @@ test-suite TestSuite
260260
zlib
261261

262262
-- dependencies exclusive to test-suite
263-
build-depends: tasty == 1.2.* || == 1.3.*,
263+
build-depends: tasty >= 1.2 && < 1.5,
264264
tasty-hunit == 0.10.*,
265265
tasty-quickcheck == 0.10.*,
266266
QuickCheck >= 2.11 && <2.15,
267-
aeson == 1.4.* || == 1.5.*,
267+
aeson == 1.4.* || == 1.5.* || == 2.0.*,
268268
vector == 0.12.*,
269269
unordered-containers >=0.2.8.0 && <0.3,
270270
temporary >= 1.2 && < 1.4

hackage-security/tests/TestSuite/JSON.hs

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE CPP #-}
12
{-# OPTIONS_GHC -fno-warn-orphans #-}
23
module TestSuite.JSON (
34
prop_roundtrip_canonical,
@@ -21,26 +22,30 @@ import Text.JSON.Canonical
2122
import Data.Aeson (Value (..), eitherDecode)
2223
import Data.String (fromString)
2324
import qualified Data.Vector as V
25+
#if MIN_VERSION_aeson(2,0,0)
26+
import qualified Data.Aeson.KeyMap as KM
27+
#else
2428
import qualified Data.HashMap.Strict as HM
29+
#endif
2530

2631
-- text
2732
import qualified Data.Text as Text
2833

2934
prop_aeson_canonical, prop_roundtrip_canonical, prop_roundtrip_pretty, prop_canonical_pretty
30-
:: JSValue -> Bool
35+
:: JSValue -> Property
3136

3237
prop_roundtrip_canonical jsval =
33-
parseCanonicalJSON (renderCanonicalJSON jsval) == Right (canonicalise jsval)
38+
parseCanonicalJSON (renderCanonicalJSON jsval) === Right (canonicalise jsval)
3439

3540
prop_roundtrip_pretty jsval =
36-
parseCanonicalJSON (BS.pack (prettyCanonicalJSON jsval)) == Right jsval
41+
parseCanonicalJSON (BS.pack (prettyCanonicalJSON jsval)) === Right jsval
3742

3843
prop_canonical_pretty jsval =
39-
parseCanonicalJSON (renderCanonicalJSON jsval) ==
44+
parseCanonicalJSON (renderCanonicalJSON jsval) ===
4045
fmap canonicalise (parseCanonicalJSON (BS.pack (prettyCanonicalJSON jsval)))
4146

4247
prop_aeson_canonical jsval =
43-
eitherDecode (renderCanonicalJSON jsval) == Right (toAeson (canonicalise jsval))
48+
eitherDecode (renderCanonicalJSON jsval) === Right (toAeson (canonicalise jsval))
4449

4550
canonicalise :: JSValue -> JSValue
4651
canonicalise v@JSNull = v
@@ -84,7 +89,11 @@ toAeson (JSBool b) = Bool b
8489
toAeson (JSNum n) = Number (fromIntegral n)
8590
toAeson (JSString s) = String (fromString s)
8691
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
8795
toAeson (JSObject xs) = Object $ HM.fromList [ (fromString k, toAeson v) | (k, v) <- xs ]
96+
#endif
8897

8998
instance Arbitrary Int54 where
9099
arbitrary = fromIntegral <$>

0 commit comments

Comments
 (0)