@@ -10,6 +10,11 @@ import Data.Aeson.Parser (value)
1010import Data.Aeson.Types
1111import Data.ByteString.Builder (toLazyByteString)
1212import Data.Int (Int8)
13+import Data.Sequence (Seq)
14+import Data.DList (DList)
15+import Data.Hashable (Hashable)
16+import Data.HashMap.Strict (HashMap)
17+import Data.Map (Map)
1318import Data.List.NonEmpty (NonEmpty)
1419import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay, UTCTime,
1520 ZonedTime)
@@ -64,6 +69,12 @@ roundTripNoEnc eq _ i =
6469roundTripEq :: (Eq a, FromJSON a, ToJSON a, Show a) => a -> a -> Property
6570roundTripEq x y = roundTripEnc (===) x y .&&. roundTripNoEnc (===) x y
6671
72+-- We test keys by encoding HashMap and Map with it
73+roundTripKey
74+ :: (Ord a, Hashable a, FromJSONKey a, ToJSONKey a, Show a)
75+ => a -> HashMap a Int -> Map a Int -> Property
76+roundTripKey _ h m = roundTripEq h h .&&. roundTripEq m m
77+
6778infix 4 ==~
6879(==~) :: (ApproxEq a, Show a) => a -> a -> Property
6980x ==~ y =
@@ -152,6 +163,8 @@ tests = testGroup "properties" [
152163 , testProperty "Proxy" $ roundTripEq (undefined :: Proxy Int)
153164 , testProperty "Tagged" $ roundTripEq (undefined :: Tagged Int Char)
154165 , testProperty "Const" $ roundTripEq (undefined :: Const Int Char)
166+ , testProperty "DList" $ roundTripEq (undefined :: DList Int)
167+ , testProperty "Seq" $ roundTripEq (undefined :: Seq Int)
155168 , testGroup "ghcGenerics" [
156169 testProperty "OneConstructor" $ roundTripEq OneConstructor
157170 , testProperty "Product2" $ roundTripEq (undefined :: Product2 Int Bool)
@@ -159,6 +172,14 @@ tests = testGroup "properties" [
159172 , testProperty "Sum4" $ roundTripEq (undefined :: S4)
160173 ]
161174 ]
175+ , testGroup "roundTrip Key"
176+ [ testProperty "Bool" $ roundTripKey True
177+ , testProperty "Text" $ roundTripKey (undefined :: T.Text)
178+ , testProperty "String" $ roundTripKey (undefined :: String)
179+ , testProperty "Int" $ roundTripKey (undefined :: Int)
180+ , testProperty "[Text]" $ roundTripKey (undefined :: [T.Text])
181+ , testProperty "(Int,Char)" $ roundTripKey (undefined :: (Int,Char))
182+ ]
162183 , testGroup "toFromJSON" [
163184 testProperty "Integer" (toFromJSON :: Integer -> Property)
164185 , testProperty "Double" (toFromJSON :: Double -> Property)