on master help sign in
No bitwise comparison on ToJSON/ToEncoding results (gh-340)
5cd5d79Bryan O'Sullivan
tests/DataFamilies/Properties.hs+3−3
@@ -61,11 +61,11 @@ tests = testGroup "data families" [
61 , testProperty "ApproxDefault" $
61 , testProperty "ApproxDefault" $
62 thApproxToJSONDefault `sameAs` thApproxToEncodingDefault
62 thApproxToJSONDefault `sameAs` thApproxToEncodingDefault
63 , testProperty "SomeType2ElemArray" $
63 , testProperty "SomeType2ElemArray" $
64− thSomeTypeToJSON2ElemArray `sameAsV` thSomeTypeToEncoding2ElemArray
64+ thSomeTypeToJSON2ElemArray `sameAs` thSomeTypeToEncoding2ElemArray
65 , testProperty "SomeTypeTaggedObject" $
65 , testProperty "SomeTypeTaggedObject" $
66− thSomeTypeToJSONTaggedObject `sameAsV` thSomeTypeToEncodingTaggedObject
66+ thSomeTypeToJSONTaggedObject `sameAs` thSomeTypeToEncodingTaggedObject
67 , testProperty "SomeTypeObjectWithSingleField" $
67 , testProperty "SomeTypeObjectWithSingleField" $
68− thSomeTypeToJSONObjectWithSingleField `sameAsV`
68+ thSomeTypeToJSONObjectWithSingleField `sameAs`
69 thSomeTypeToEncodingObjectWithSingleField
69 thSomeTypeToEncodingObjectWithSingleField
70 ]
70 ]
71 ]
71 ]
tests/Properties.hs+6−11
@@ -72,16 +72,11 @@ modifyFailureProp orig added =
72 result :: Result ()
72 result :: Result ()
73 result = parse parser ()
73 result = parse parser ()
74
74
75−-- | Perform a bit-for-bit comparison of two encoding methods.
75+-- | Perform a structural comparison of the results of two encoding
76+-- methods. Compares decoded values to account for HashMap-driven
77+-- variation in JSON object key ordering.
76sameAs :: (a -> Value) -> (a -> Encoding) -> a -> Property
78sameAs :: (a -> Value) -> (a -> Encoding) -> a -> Property
77sameAs toVal toEnc v =
79sameAs toVal toEnc v =
78− toLazyByteString (encodeToBuilder (toVal v)) ===
79− toLazyByteString (fromEncoding (toEnc v))
80−
81−-- | Behaves like 'sameAs', but compares decoded values to account for
82−-- HashMap-driven variation in JSON object key ordering.
83−sameAsV :: (a -> Value) -> (a -> Encoding) -> a -> Property
84−sameAsV toVal toEnc v =
85 eitherDecode (toLazyByteString (fromEncoding (toEnc v))) === Right (toVal v)
80 eitherDecode (toLazyByteString (fromEncoding (toEnc v))) === Right (toVal v)
86
81
87type P6 = Product6 Int Bool String (Approx Double) (Int, Approx Double) ()
82type P6 = Product6 Int Bool String (Approx Double) (Int, Approx Double) ()
@@ -202,11 +197,11 @@ tests = testGroup "properties" [
202 , testProperty "ApproxDefault" $
197 , testProperty "ApproxDefault" $
203 thApproxToJSONDefault `sameAs` thApproxToEncodingDefault
198 thApproxToJSONDefault `sameAs` thApproxToEncodingDefault
204 , testProperty "SomeType2ElemArray" $
199 , testProperty "SomeType2ElemArray" $
205− thSomeTypeToJSON2ElemArray `sameAsV` thSomeTypeToEncoding2ElemArray
200+ thSomeTypeToJSON2ElemArray `sameAs` thSomeTypeToEncoding2ElemArray
206 , testProperty "SomeTypeTaggedObject" $
201 , testProperty "SomeTypeTaggedObject" $
207− thSomeTypeToJSONTaggedObject `sameAsV` thSomeTypeToEncodingTaggedObject
202+ thSomeTypeToJSONTaggedObject `sameAs` thSomeTypeToEncodingTaggedObject
208 , testProperty "SomeTypeObjectWithSingleField" $
203 , testProperty "SomeTypeObjectWithSingleField" $
209− thSomeTypeToJSONObjectWithSingleField `sameAsV`
204+ thSomeTypeToJSONObjectWithSingleField `sameAs`
210 thSomeTypeToEncodingObjectWithSingleField
205 thSomeTypeToEncodingObjectWithSingleField
211 ]
206 ]
212 ]
207 ]