Skip to content

Commit 35a50d1

Browse files
author
Poscat
committed
Add th property tests for TaggedFlatObject
1 parent 9d4eaf2 commit 35a50d1

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed

tests/Encoders.hs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,16 @@ thNullaryParseJSONTaggedObject :: Value -> Parser Nullary
4747
thNullaryParseJSONTaggedObject = $(mkParseJSON optsTaggedObject ''Nullary)
4848

4949

50+
thNullaryToJSONTaggedFlatObject :: Nullary -> Value
51+
thNullaryToJSONTaggedFlatObject = $(mkToJSON optsTaggedFlatObject ''Nullary)
52+
53+
thNullaryToEncodingTaggedFlatObject :: Nullary -> Encoding
54+
thNullaryToEncodingTaggedFlatObject = $(mkToEncoding optsTaggedFlatObject ''Nullary)
55+
56+
thNullaryParseJSONTaggedFlatObject :: Value -> Parser Nullary
57+
thNullaryParseJSONTaggedFlatObject = $(mkParseJSON optsTaggedFlatObject ''Nullary)
58+
59+
5060
thNullaryToJSONObjectWithSingleField :: Nullary -> Value
5161
thNullaryToJSONObjectWithSingleField =
5262
$(mkToJSON optsObjectWithSingleField ''Nullary)
@@ -170,6 +180,25 @@ thSomeTypeLiftParseJSONTaggedObject :: LiftParseJSON SomeType a
170180
thSomeTypeLiftParseJSONTaggedObject = $(mkLiftParseJSON optsTaggedObject ''SomeType)
171181

172182

183+
thSomeTypeToJSONTaggedFlatObject :: SomeType Int -> Value
184+
thSomeTypeToJSONTaggedFlatObject = $(mkToJSON optsTaggedFlatObject ''SomeType)
185+
186+
thSomeTypeToEncodingTaggedFlatObject :: SomeType Int -> Encoding
187+
thSomeTypeToEncodingTaggedFlatObject = $(mkToEncoding optsTaggedFlatObject ''SomeType)
188+
189+
thSomeTypeLiftToJSONTaggedFlatObject :: LiftToJSON SomeType a
190+
thSomeTypeLiftToJSONTaggedFlatObject = $(mkLiftToJSON optsTaggedFlatObject ''SomeType)
191+
192+
thSomeTypeLiftToEncodingTaggedFlatObject :: LiftToEncoding SomeType a
193+
thSomeTypeLiftToEncodingTaggedFlatObject = $(mkLiftToEncoding optsTaggedFlatObject ''SomeType)
194+
195+
thSomeTypeParseJSONTaggedFlatObject :: Value -> Parser (SomeType Int)
196+
thSomeTypeParseJSONTaggedFlatObject = $(mkParseJSON optsTaggedFlatObject ''SomeType)
197+
198+
thSomeTypeLiftParseJSONTaggedFlatObject :: LiftParseJSON SomeType a
199+
thSomeTypeLiftParseJSONTaggedFlatObject = $(mkLiftParseJSON optsTaggedFlatObject ''SomeType)
200+
201+
173202
thSomeTypeToJSONObjectWithSingleField :: SomeType Int -> Value
174203
thSomeTypeToJSONObjectWithSingleField = $(mkToJSON optsObjectWithSingleField ''SomeType)
175204

tests/PropertyTH.hs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,12 +22,14 @@ templateHaskellTests =
2222
testProperty "string" (isString . thNullaryToJSONString)
2323
, testProperty "2ElemArray" (is2ElemArray . thNullaryToJSON2ElemArray)
2424
, testProperty "TaggedObject" (isNullaryTaggedObject . thNullaryToJSONTaggedObject)
25+
, testProperty "TaggedFlatObject" (isNullaryTaggedObject . thNullaryToJSONTaggedFlatObject)
2526
, testProperty "ObjectWithSingleField" (isObjectWithSingleField . thNullaryToJSONObjectWithSingleField)
2627

2728
, testGroup "roundTrip" [
2829
testProperty "string" (toParseJSON thNullaryParseJSONString thNullaryToJSONString)
2930
, testProperty "2ElemArray" (toParseJSON thNullaryParseJSON2ElemArray thNullaryToJSON2ElemArray)
3031
, testProperty "TaggedObject" (toParseJSON thNullaryParseJSONTaggedObject thNullaryToJSONTaggedObject)
32+
, testProperty "TaggedFlatObject" (toParseJSON thNullaryParseJSONTaggedFlatObject thNullaryToJSONTaggedFlatObject)
3133
, testProperty "ObjectWithSingleField" (toParseJSON thNullaryParseJSONObjectWithSingleField thNullaryToJSONObjectWithSingleField)
3234
]
3335
]
@@ -38,14 +40,17 @@ templateHaskellTests =
3840
, testGroup "SomeType" [
3941
testProperty "2ElemArray" (is2ElemArray . thSomeTypeToJSON2ElemArray)
4042
, testProperty "TaggedObject" (isTaggedObject . thSomeTypeToJSONTaggedObject)
43+
, testProperty "TaggedFlatObject" (isTaggedObject . thSomeTypeToJSONTaggedFlatObject)
4144
, testProperty "ObjectWithSingleField" (isObjectWithSingleField . thSomeTypeToJSONObjectWithSingleField)
4245
, testGroup "roundTrip" [
4346
testProperty "2ElemArray" (toParseJSON thSomeTypeParseJSON2ElemArray thSomeTypeToJSON2ElemArray)
4447
, testProperty "TaggedObject" (toParseJSON thSomeTypeParseJSONTaggedObject thSomeTypeToJSONTaggedObject)
48+
, testProperty "TaggedFlatObject" (toParseJSON thSomeTypeParseJSONTaggedFlatObject thSomeTypeToJSONTaggedFlatObject)
4549
, testProperty "ObjectWithSingleField" (toParseJSON thSomeTypeParseJSONObjectWithSingleField thSomeTypeToJSONObjectWithSingleField)
4650

4751
, testProperty "2ElemArray unary" (toParseJSON1 thSomeTypeLiftParseJSON2ElemArray thSomeTypeLiftToJSON2ElemArray)
4852
, testProperty "TaggedObject unary" (toParseJSON1 thSomeTypeLiftParseJSONTaggedObject thSomeTypeLiftToJSONTaggedObject)
53+
, testProperty "TaggedFlatObject unary" (toParseJSON1 thSomeTypeLiftParseJSONTaggedFlatObject thSomeTypeLiftToJSONTaggedFlatObject)
4954
, testProperty "ObjectWithSingleField unary" (toParseJSON1 thSomeTypeLiftParseJSONObjectWithSingleField thSomeTypeLiftToJSONObjectWithSingleField)
5055

5156
]
@@ -87,6 +92,8 @@ templateHaskellTests =
8792
thNullaryToJSON2ElemArray `sameAs` thNullaryToEncoding2ElemArray
8893
, testProperty "NullaryTaggedObject" $
8994
thNullaryToJSONTaggedObject `sameAs` thNullaryToEncodingTaggedObject
95+
, testProperty "NullaryTaggedFlatObject" $
96+
thNullaryToJSONTaggedFlatObject `sameAs` thNullaryToEncodingTaggedFlatObject
9097
, testProperty "NullaryObjectWithSingleField" $
9198
thNullaryToJSONObjectWithSingleField `sameAs`
9299
thNullaryToEncodingObjectWithSingleField
@@ -112,6 +119,13 @@ templateHaskellTests =
112119
, testProperty "SomeTypeTaggedObject unary agree" $
113120
thSomeTypeToEncodingTaggedObject `sameAs1Agree` thSomeTypeLiftToEncodingTaggedObject
114121

122+
, testProperty "SomeTypeTaggedFlatObject" $
123+
thSomeTypeToJSONTaggedFlatObject `sameAs` thSomeTypeToEncodingTaggedFlatObject
124+
, testProperty "SomeTypeTaggedFlatObject unary" $
125+
thSomeTypeLiftToJSONTaggedFlatObject `sameAs1` thSomeTypeLiftToEncodingTaggedFlatObject
126+
, testProperty "SomeTypeTaggedFlatObject unary agree" $
127+
thSomeTypeToEncodingTaggedFlatObject `sameAs1Agree` thSomeTypeLiftToEncodingTaggedFlatObject
128+
115129
, testProperty "SomeTypeObjectWithSingleField" $
116130
thSomeTypeToJSONObjectWithSingleField `sameAs` thSomeTypeToEncodingObjectWithSingleField
117131
, testProperty "SomeTypeObjectWithSingleField unary" $

0 commit comments

Comments
 (0)