Skip to content

Commit

Permalink
Adapt to new aeson
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-volkov committed Oct 10, 2021
1 parent 9d2de93 commit 34f70d9
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 6 deletions.
4 changes: 2 additions & 2 deletions jsonifier.cabal
Expand Up @@ -64,7 +64,7 @@ test-suite test
other-modules:
Main.Util.HedgehogGens
build-depends:
aeson >=1.4.7.1 && <2,
aeson >=2 && <3,
hedgehog >=1.0.3 && <2,
jsonifier,
numeric-limits >=0.1 && <0.2,
Expand All @@ -83,7 +83,7 @@ benchmark bench
default-extensions: BangPatterns, ConstraintKinds, DataKinds, DefaultSignatures, DeriveDataTypeable, DeriveFoldable, DeriveFunctor, DeriveGeneric, DeriveTraversable, EmptyDataDecls, FlexibleContexts, FlexibleInstances, FunctionalDependencies, GADTs, GeneralizedNewtypeDeriving, InstanceSigs, LambdaCase, LiberalTypeSynonyms, MagicHash, MultiParamTypeClasses, MultiWayIf, NoImplicitPrelude, NoMonomorphismRestriction, OverloadedStrings, PatternGuards, ParallelListComp, QuasiQuotes, RankNTypes, RecordWildCards, ScopedTypeVariables, StandaloneDeriving, StrictData, TemplateHaskell, TupleSections, TypeApplications, TypeFamilies, TypeOperators, UnboxedTuples, ViewPatterns
default-language: Haskell2010
build-depends:
aeson >=1.5.4.1 && <1.6,
aeson >=2 && <3,
buffer-builder >=0.2.4.7 && <0.3,
gauge >=0.2.5 && <0.3,
jsonifier,
Expand Down
9 changes: 5 additions & 4 deletions test/Main.hs
Expand Up @@ -5,7 +5,8 @@ import Hedgehog
import Hedgehog.Main
import qualified Data.Aeson as A
import qualified Jsonifier as J
import qualified Data.HashMap.Strict as HashMap
import qualified Data.Aeson.Key as AesonKey
import qualified Data.Aeson.KeyMap as AesonKeyMap
import qualified Hedgehog.Gen as Gen
import qualified Hedgehog.Range as Range
import qualified Data.ByteString.Char8 as Char8ByteString
Expand Down Expand Up @@ -40,7 +41,7 @@ prop_sample =
A.Array a ->
J.array (fmap aesonJson a)
A.Object a ->
J.object (HashMap.foldMapWithKey (\ k -> (: []) . (,) k . aesonJson) a)
J.object (AesonKeyMap.foldMapWithKey (\ k -> (: []) . (,) (AesonKey.toText k) . aesonJson) a)

prop_aesonRoundtrip =
withTests 9999 $
Expand Down Expand Up @@ -142,7 +143,7 @@ sampleAeson =
ScientificStringSample a -> A.String (fromString (show a))
TextStringSample a -> A.String a
ArraySample a -> A.Array (fromList (fmap sample a))
ObjectSample a -> A.Object (fromList (fmap (fmap sample) a))
ObjectSample a -> A.Object (AesonKeyMap.fromList (fmap (bimap AesonKey.fromText sample) a))
where
realNumber a =
A.Number $
Expand Down Expand Up @@ -204,7 +205,7 @@ detectMismatchInSampleAndAeson =
\ case
A.Object b ->
a & foldMap (\ (ak, av) ->
case HashMap.lookup ak b of
case AesonKeyMap.lookup (AesonKey.fromText ak) b of
Just bv -> fmap First (detectMismatchInSampleAndAeson av bv)
Nothing -> Just (First (ObjectSample a, A.Object b))
)
Expand Down

0 comments on commit 34f70d9

Please sign in to comment.