@@ -5,7 +5,7 @@ import Data.Aeson.Parser (value)
55import Data.Aeson.Types
66import Data.Attoparsec.Number
77import Data.Data (Data)
8−import Data.Function (on)
8+import Data.Int
99import Test.Framework (Test, defaultMain, testGroup)
1010import Test.Framework.Providers.QuickCheck2 (testProperty)
1111import Test.QuickCheck (Arbitrary(..))
@@ -17,8 +17,8 @@ import qualified Data.Map as Map
1717import Data.Time.Clock (UTCTime(..))
1818import Data.Time (ZonedTime(..))
1919import Types (Foo(..), UFoo(..))
20−import Functions
2120import Instances ()
21+import Types (Approx(..), OneConstructor(..), Product2, Product6, Sum4)
2222
2323encodeDouble :: Double -> Double -> Bool
2424encodeDouble num denom
@@ -44,16 +44,6 @@ genericTo _ v = G.toJSON v == toJSON v
4444genericFrom :: (Eq a, Data a, ToJSON a) => a -> a -> Bool
4545genericFrom _ v = G.fromJSON (toJSON v) == Success v
4646
47−-- Compare equality to within a millisecond, allowing for rounding
48−-- error (ECMA 262 requires milliseconds to rounded to zero, not
49−-- rounded to nearest).
50−approxEqUTC :: UTCTime -> UTCTime -> Bool
51−approxEqUTC a b = ((==) `on` utctDay) a b &&
52− (approxEqWith 1 1 `on` ((* 1e3) . utctDayTime)) a b
53−
54−approxEqNet :: DotNetTime -> DotNetTime -> Bool
55−approxEqNet (DotNetTime a) (DotNetTime b) = approxEqUTC a b
56−
5747toFromJSON :: (Arbitrary a, Eq a, FromJSON a, ToJSON a) => a -> Bool
5848toFromJSON x = case fromJSON . toJSON $ x of
5949 Error _ -> False
@@ -79,6 +69,9 @@ modifyFailureProp orig added =
7969main :: IO ()
8070main = defaultMain tests
8171
72+type P6 = Product6 Int Bool String (Approx Double) (Int, Approx Double) ()
73+type S4 = Sum4 Int8 ZonedTime T.Text (Map.Map String Int)
74+
8275tests :: [Test]
8376tests = [
8477 testGroup "regression" [
@@ -104,15 +97,21 @@ tests = [
10497 ],
10598 testGroup "roundTrip" [
10699 testProperty "Bool" $ roundTripEq True
107− , testProperty "Double" $ roundTrip approxEq (1::Double)
100+ , testProperty "Double" $ roundTripEq (1 :: Approx Double)
108101 , testProperty "Int" $ roundTripEq (1::Int)
109102 , testProperty "Integer" $ roundTripEq (1::Integer)
110103 , testProperty "String" $ roundTripEq (""::String)
111104 , testProperty "Text" $ roundTripEq T.empty
112105 , testProperty "Foo" $ roundTripEq (undefined::Foo)
113− , testProperty "DotNetTime" $ roundTrip approxEqNet undefined
114− , testProperty "UTCTime" $ roundTrip approxEqUTC undefined
106+ , testProperty "DotNetTime" $ roundTripEq (undefined :: Approx DotNetTime)
107+ , testProperty "UTCTime" $ roundTripEq (undefined :: Approx UTCTime)
115108 , testProperty "ZonedTime" $ roundTripEq (undefined::ZonedTime)
109+ , testGroup "ghcGenerics" [
110+ testProperty "OneConstructor" $ roundTripEq OneConstructor
111+ , testProperty "Product2" $ roundTripEq (undefined :: Product2 Int Bool)
112+ , testProperty "Product6" $ roundTripEq (undefined :: P6)
113+ , testProperty "Sum4" $ roundTripEq (undefined :: S4)
114+ ]
116115 ],
117116 testGroup "toFromJSON" [
118117 testProperty "Integer" (toFromJSON :: Integer -> Bool)