@@ -33,7 +33,7 @@ import Instances ()
33
33
import Numeric.Natural (Natural )
34
34
import Test.Framework (Test , testGroup )
35
35
import Test.Framework.Providers.QuickCheck2 (testProperty )
36
- import Test.QuickCheck (Arbitrary (.. ), Property , (===) , (.&&.) , counterexample )
36
+ import Test.QuickCheck (Arbitrary (.. ), Property , Testable , (===) , (.&&.) , counterexample )
37
37
import Types
38
38
import qualified Data.Attoparsec.Lazy as L
39
39
import qualified Data.ByteString.Lazy.Char8 as L
@@ -149,6 +149,11 @@ type S4 = Sum4 Int8 ZonedTime T.Text (Map.Map String Int)
149
149
-- Value properties
150
150
--------------------------------------------------------------------------------
151
151
152
+ -- | Add the formatted @Value@ to the printed counterexample when the property
153
+ -- fails.
154
+ checkValue :: Testable a => (Value -> a ) -> Value -> Property
155
+ checkValue prop v = counterexample (L. unpack (encode v)) (prop v)
156
+
152
157
isString :: Value -> Bool
153
158
isString (String _) = True
154
159
isString _ = False
@@ -182,6 +187,12 @@ isUntaggedValueETI (Number _) = True
182
187
isUntaggedValueETI (Array a) = length a == 2
183
188
isUntaggedValueETI _ = False
184
189
190
+ isEmptyArray :: Value -> Property
191
+ isEmptyArray = checkValue isEmptyArray'
192
+
193
+ isEmptyArray' :: Value -> Bool
194
+ isEmptyArray' = (Array mempty == )
195
+
185
196
186
197
--------------------------------------------------------------------------------
187
198
@@ -427,6 +438,12 @@ tests = testGroup "properties" [
427
438
, testProperty " ObjectWithSingleField" (toParseJSON thGADTParseJSONDefault thGADTToJSONDefault)
428
439
]
429
440
]
441
+ , testGroup " OneConstructor" [
442
+ testProperty " default" (isEmptyArray . thOneConstructorToJSONDefault)
443
+ , testGroup " roundTrip" [
444
+ testProperty " default" (toParseJSON thOneConstructorParseJSONDefault thOneConstructorToJSONDefault)
445
+ ]
446
+ ]
430
447
]
431
448
, testGroup " toEncoding" [
432
449
testProperty " NullaryString" $
@@ -466,6 +483,9 @@ tests = testGroup "properties" [
466
483
thSomeTypeLiftToJSONObjectWithSingleField `sameAs1` thSomeTypeLiftToEncodingObjectWithSingleField
467
484
, testProperty " SomeTypeObjectWithSingleField unary agree" $
468
485
thSomeTypeToEncodingObjectWithSingleField `sameAs1Agree` thSomeTypeLiftToEncodingObjectWithSingleField
486
+
487
+ , testProperty " OneConstructor" $
488
+ thOneConstructorToJSONDefault `sameAs` thOneConstructorToEncodingDefault
469
489
]
470
490
]
471
491
]
0 commit comments