@@ -14,7 +14,7 @@ import Encoders
14import Instances ()
14import Instances ()
15import Test.Framework (Test, testGroup)
15import Test.Framework (Test, testGroup)
16import Test.Framework.Providers.QuickCheck2 (testProperty)
16import Test.Framework.Providers.QuickCheck2 (testProperty)
17−import Test.QuickCheck (Arbitrary(..), Property, (===))
17+import Test.QuickCheck (Arbitrary(..), Property, (===), (.&&.))
18import Types
18import Types
19import qualified Data.Attoparsec.Lazy as L
19import qualified Data.Attoparsec.Lazy as L
20import qualified Data.ByteString.Lazy.Char8 as L
20import qualified Data.ByteString.Lazy.Char8 as L
@@ -39,16 +39,23 @@ toParseJSON parsejson tojson x =
39 IError path msg -> failure "parse" (formatError path msg) x
39 IError path msg -> failure "parse" (formatError path msg) x
40 ISuccess x' -> x === x'
40 ISuccess x' -> x === x'
42−roundTrip :: (FromJSON a, ToJSON a, Show a) =>
42+roundTripEnc :: (FromJSON a, ToJSON a, Show a) =>
43 (a -> a -> Property) -> a -> a -> Property
43 (a -> a -> Property) -> a -> a -> Property
44−roundTrip eq _ i =
44+roundTripEnc eq _ i =
45− case fmap ifromJSON . L.parse value . encode . toJSON $ i of
45+ case fmap ifromJSON . L.parse value . encode $ i of
46 L.Done _ (ISuccess v) -> v `eq` i
46 L.Done _ (ISuccess v) -> v `eq` i
47 L.Done _ (IError path err) -> failure "fromJSON" (formatError path err) i
47 L.Done _ (IError path err) -> failure "fromJSON" (formatError path err) i
48 L.Fail _ _ err -> failure "parse" err i
48 L.Fail _ _ err -> failure "parse" err i
50+roundTripNoEnc :: (FromJSON a, ToJSON a, Show a) =>
51+ (a -> a -> Property) -> a -> a -> Property
52+roundTripNoEnc eq _ i =
53+ case ifromJSON . toJSON $ i of
54+ (ISuccess v) -> v `eq` i
55+ (IError path err) -> failure "fromJSON" (formatError path err) i
50roundTripEq :: (Eq a, FromJSON a, ToJSON a, Show a) => a -> a -> Property
57roundTripEq :: (Eq a, FromJSON a, ToJSON a, Show a) => a -> a -> Property
51−roundTripEq x y = roundTrip (===) x y
58+roundTripEq x y = roundTripEnc (===) x y .&&. roundTripNoEnc (===) x y
53toFromJSON :: (Arbitrary a, Eq a, FromJSON a, ToJSON a, Show a) => a -> Property
60toFromJSON :: (Arbitrary a, Eq a, FromJSON a, ToJSON a, Show a) => a -> Property
54toFromJSON x = case ifromJSON (toJSON x) of
61toFromJSON x = case ifromJSON (toJSON x) of