@@ -6,6 +6,7 @@ import Data.Aeson.Types
66import Data.Attoparsec.Number
77import Test.Framework (Test, defaultMain, testGroup)
88import Test.Framework.Providers.QuickCheck2 (testProperty)
9+import Test.QuickCheck (Arbitrary)
910import qualified Data.ByteString.Lazy.Char8 as L
1011import qualified Data.Attoparsec.Lazy as L
1112
@@ -39,6 +40,11 @@ approxEq a b = a == b ||
3940 maxAbsoluteError = 1e-15
4041 maxRelativeError = 1e-15
4142
43+toFromJSON :: (Arbitrary a, Eq a, FromJSON a, ToJSON a) => a -> Bool
44+toFromJSON x = case fromJSON . toJSON $ x of
45+ Error _ -> False
46+ Success x' -> x == x'
47+
4248main :: IO ()
4349main = defaultMain tests
4450
@@ -52,5 +58,12 @@ tests = [
5258 testProperty "roundTripBool" roundTripBool
5359 , testProperty "roundTripDouble" roundTripDouble
5460 , testProperty "roundTripInteger" roundTripInteger
61+ ],
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)
5568 ]
5669 ]