@@ -12,6 +12,9 @@ import Data.ByteString.Builder (toLazyByteString)
1212import Data.Int (Int8)
1313import Data.Sequence (Seq)
1414import Data.DList (DList)
15+import Data.Hashable (Hashable)
16+import Data.HashMap.Strict (HashMap)
17+import Data.Map (Map)
1518import Data.List.NonEmpty (NonEmpty)
1619import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay, UTCTime,
1720 ZonedTime)
@@ -66,6 +69,12 @@ roundTripNoEnc eq _ i =
6669roundTripEq :: (Eq a, FromJSON a, ToJSON a, Show a) => a -> a -> Property
6770roundTripEq x y = roundTripEnc (===) x y .&&. roundTripNoEnc (===) x y
6871
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+
6978infix 4 ==~
7079(==~) :: (ApproxEq a, Show a) => a -> a -> Property
7180x ==~ y =
@@ -163,6 +172,14 @@ tests = testGroup "properties" [
163172 , testProperty "Sum4" $ roundTripEq (undefined :: S4)
164173 ]
165174 ]
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+ ]
166183 , testGroup "toFromJSON" [
167184 testProperty "Integer" (toFromJSON :: Integer -> Property)
168185 , testProperty "Double" (toFromJSON :: Double -> Property)