@@ -6,6 +6,7 @@ import Data.Aeson.Types
6import Data.Attoparsec.Number
6import Data.Attoparsec.Number
7import Test.Framework (Test, defaultMain, testGroup)
7import Test.Framework (Test, defaultMain, testGroup)
8import Test.Framework.Providers.QuickCheck2 (testProperty)
8import Test.Framework.Providers.QuickCheck2 (testProperty)
9+import Test.QuickCheck (Arbitrary)
9import qualified Data.ByteString.Lazy.Char8 as L
10import qualified Data.ByteString.Lazy.Char8 as L
10import qualified Data.Attoparsec.Lazy as L
11import qualified Data.Attoparsec.Lazy as L
@@ -39,6 +40,11 @@ approxEq a b = a == b ||
39 maxAbsoluteError = 1e-15
40 maxAbsoluteError = 1e-15
40 maxRelativeError = 1e-15
41 maxRelativeError = 1e-15
43+toFromJSON :: (Arbitrary a, Eq a, FromJSON a, ToJSON a) => a -> Bool
44+toFromJSON x = case fromJSON . toJSON $ x of
46+ Success x' -> x == x'
42main :: IO ()
48main :: IO ()
43main = defaultMain tests
49main = defaultMain tests
@@ -52,5 +58,12 @@ tests = [
52 testProperty "roundTripBool" roundTripBool
58 testProperty "roundTripBool" roundTripBool
53 , testProperty "roundTripDouble" roundTripDouble
59 , testProperty "roundTripDouble" roundTripDouble
54 , testProperty "roundTripInteger" roundTripInteger
60 , testProperty "roundTripInteger" roundTripInteger
62+ testGroup "toFromJSON" [
63+ testProperty "Integer" (toFromJSON :: Integer -> Bool)
64+ , testProperty "Double" (toFromJSON :: Double -> Bool)
65+ , testProperty "Maybe Integer" (toFromJSON :: Maybe Integer -> Bool)
66+ , testProperty "Either Integer Double" (toFromJSON :: Either Integer Double -> Bool)
67+ , testProperty "Either Integer Integer" (toFromJSON :: Either Integer Integer -> Bool)