@@ -10,6 +10,11 @@ import Data.Aeson.Parser (value)
10import Data.Aeson.Types
10import Data.Aeson.Types
11import Data.ByteString.Builder (toLazyByteString)
11import Data.ByteString.Builder (toLazyByteString)
12import Data.Int (Int8)
12import Data.Int (Int8)
13+import Data.Sequence (Seq)
14+import Data.DList (DList)
15+import Data.Hashable (Hashable)
16+import Data.HashMap.Strict (HashMap)
13import Data.List.NonEmpty (NonEmpty)
18import Data.List.NonEmpty (NonEmpty)
14import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay, UTCTime,
19import Data.Time (Day, LocalTime, NominalDiffTime, TimeOfDay, UTCTime,
15 ZonedTime)
20 ZonedTime)
@@ -64,6 +69,12 @@ roundTripNoEnc eq _ i =
64roundTripEq :: (Eq a, FromJSON a, ToJSON a, Show a) => a -> a -> Property
69roundTripEq :: (Eq a, FromJSON a, ToJSON a, Show a) => a -> a -> Property
65roundTripEq x y = roundTripEnc (===) x y .&&. roundTripNoEnc (===) x y
70roundTripEq x y = roundTripEnc (===) x y .&&. roundTripNoEnc (===) x y
72+-- We test keys by encoding HashMap and Map with it
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
67infix 4 ==~
78infix 4 ==~
68(==~) :: (ApproxEq a, Show a) => a -> a -> Property
79(==~) :: (ApproxEq a, Show a) => a -> a -> Property
@@ -152,6 +163,8 @@ tests = testGroup "properties" [
152 , testProperty "Proxy" $ roundTripEq (undefined :: Proxy Int)
163 , testProperty "Proxy" $ roundTripEq (undefined :: Proxy Int)
153 , testProperty "Tagged" $ roundTripEq (undefined :: Tagged Int Char)
164 , testProperty "Tagged" $ roundTripEq (undefined :: Tagged Int Char)
154 , testProperty "Const" $ roundTripEq (undefined :: Const Int Char)
165 , testProperty "Const" $ roundTripEq (undefined :: Const Int Char)
166+ , testProperty "DList" $ roundTripEq (undefined :: DList Int)
167+ , testProperty "Seq" $ roundTripEq (undefined :: Seq Int)
155 , testGroup "ghcGenerics" [
168 , testGroup "ghcGenerics" [
156 testProperty "OneConstructor" $ roundTripEq OneConstructor
169 testProperty "OneConstructor" $ roundTripEq OneConstructor
157 , testProperty "Product2" $ roundTripEq (undefined :: Product2 Int Bool)
170 , testProperty "Product2" $ roundTripEq (undefined :: Product2 Int Bool)
@@ -159,6 +172,14 @@ tests = testGroup "properties" [
159 , testProperty "Sum4" $ roundTripEq (undefined :: S4)
172 , testProperty "Sum4" $ roundTripEq (undefined :: S4)
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))
162 , testGroup "toFromJSON" [
183 , testGroup "toFromJSON" [
163 testProperty "Integer" (toFromJSON :: Integer -> Property)
184 testProperty "Integer" (toFromJSON :: Integer -> Property)
164 , testProperty "Double" (toFromJSON :: Double -> Property)
185 , testProperty "Double" (toFromJSON :: Double -> Property)