@@ -5,7 +5,7 @@ import Data.Aeson.Parser (value)
5import Data.Aeson.Types
5import Data.Aeson.Types
6import Data.Attoparsec.Number
6import Data.Attoparsec.Number
7import Data.Data (Data)
7import Data.Data (Data)
8−import Data.Function (on)
8+import Data.Int
9import Test.Framework (Test, defaultMain, testGroup)
9import Test.Framework (Test, defaultMain, testGroup)
10import Test.Framework.Providers.QuickCheck2 (testProperty)
10import Test.Framework.Providers.QuickCheck2 (testProperty)
11import Test.QuickCheck (Arbitrary(..))
11import Test.QuickCheck (Arbitrary(..))
@@ -17,8 +17,8 @@ import qualified Data.Map as Map
17import Data.Time.Clock (UTCTime(..))
17import Data.Time.Clock (UTCTime(..))
18import Data.Time (ZonedTime(..))
18import Data.Time (ZonedTime(..))
19import Types (Foo(..), UFoo(..))
19import Types (Foo(..), UFoo(..))
21import Instances ()
20import Instances ()
21+import Types (Approx(..), OneConstructor(..), Product2, Product6, Sum4)
23encodeDouble :: Double -> Double -> Bool
23encodeDouble :: Double -> Double -> Bool
24encodeDouble num denom
24encodeDouble num denom
@@ -44,16 +44,6 @@ genericTo _ v = G.toJSON v == toJSON v
44genericFrom :: (Eq a, Data a, ToJSON a) => a -> a -> Bool
44genericFrom :: (Eq a, Data a, ToJSON a) => a -> a -> Bool
45genericFrom _ v = G.fromJSON (toJSON v) == Success v
45genericFrom _ v = G.fromJSON (toJSON v) == Success v
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
54−approxEqNet :: DotNetTime -> DotNetTime -> Bool
55−approxEqNet (DotNetTime a) (DotNetTime b) = approxEqUTC a b
57toFromJSON :: (Arbitrary a, Eq a, FromJSON a, ToJSON a) => a -> Bool
47toFromJSON :: (Arbitrary a, Eq a, FromJSON a, ToJSON a) => a -> Bool
58toFromJSON x = case fromJSON . toJSON $ x of
48toFromJSON x = case fromJSON . toJSON $ x of
59 Error _ -> False
49 Error _ -> False
@@ -79,6 +69,9 @@ modifyFailureProp orig added =
79main :: IO ()
69main :: IO ()
80main = defaultMain tests
70main = defaultMain tests
72+type P6 = Product6 Int Bool String (Approx Double) (Int, Approx Double) ()
73+type S4 = Sum4 Int8 ZonedTime T.Text (Map.Map String Int)
82tests :: [Test]
75tests :: [Test]
84 testGroup "regression" [
77 testGroup "regression" [
@@ -104,15 +97,21 @@ tests = [
105 testGroup "roundTrip" [
98 testGroup "roundTrip" [
106 testProperty "Bool" $ roundTripEq True
99 testProperty "Bool" $ roundTripEq True
107− , testProperty "Double" $ roundTrip approxEq (1::Double)
100+ , testProperty "Double" $ roundTripEq (1 :: Approx Double)
108 , testProperty "Int" $ roundTripEq (1::Int)
101 , testProperty "Int" $ roundTripEq (1::Int)
109 , testProperty "Integer" $ roundTripEq (1::Integer)
102 , testProperty "Integer" $ roundTripEq (1::Integer)
110 , testProperty "String" $ roundTripEq (""::String)
103 , testProperty "String" $ roundTripEq (""::String)
111 , testProperty "Text" $ roundTripEq T.empty
104 , testProperty "Text" $ roundTripEq T.empty
112 , testProperty "Foo" $ roundTripEq (undefined::Foo)
105 , testProperty "Foo" $ roundTripEq (undefined::Foo)
113− , testProperty "DotNetTime" $ roundTrip approxEqNet undefined
106+ , testProperty "DotNetTime" $ roundTripEq (undefined :: Approx DotNetTime)
114− , testProperty "UTCTime" $ roundTrip approxEqUTC undefined
107+ , testProperty "UTCTime" $ roundTripEq (undefined :: Approx UTCTime)
115 , testProperty "ZonedTime" $ roundTripEq (undefined::ZonedTime)
108 , 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)
117 testGroup "toFromJSON" [
116 testGroup "toFromJSON" [
118 testProperty "Integer" (toFromJSON :: Integer -> Bool)
117 testProperty "Integer" (toFromJSON :: Integer -> Bool)