on master help sign in
Basic tests for Generic toJSON.
4d1e71dEwout
tests/Encoders.hs+27
@@ -55,6 +55,9 @@ thNullaryParseJSONObjectWithSingleField = $(mkParseJSON optsObjectWithSingleFiel
55gNullaryToJSONString :: Nullary -> Value
55gNullaryToJSONString :: Nullary -> Value
56gNullaryToJSONString = genericToJSON defaultOptions
56gNullaryToJSONString = genericToJSON defaultOptions
57
57
58+gNullaryToEncodingString :: Nullary -> Encoding
59+gNullaryToEncodingString = genericToEncoding defaultOptions
60+
58gNullaryParseJSONString :: Value -> Parser Nullary
61gNullaryParseJSONString :: Value -> Parser Nullary
59gNullaryParseJSONString = genericParseJSON defaultOptions
62gNullaryParseJSONString = genericParseJSON defaultOptions
60
63
@@ -62,6 +65,9 @@ gNullaryParseJSONString = genericParseJSON defaultOptions
62gNullaryToJSON2ElemArray :: Nullary -> Value
65gNullaryToJSON2ElemArray :: Nullary -> Value
63gNullaryToJSON2ElemArray = genericToJSON opts2ElemArray
66gNullaryToJSON2ElemArray = genericToJSON opts2ElemArray
64
67
68+gNullaryToEncoding2ElemArray :: Nullary -> Encoding
69+gNullaryToEncoding2ElemArray = genericToEncoding opts2ElemArray
70+
65gNullaryParseJSON2ElemArray :: Value -> Parser Nullary
71gNullaryParseJSON2ElemArray :: Value -> Parser Nullary
66gNullaryParseJSON2ElemArray = genericParseJSON opts2ElemArray
72gNullaryParseJSON2ElemArray = genericParseJSON opts2ElemArray
67
73
@@ -69,6 +75,9 @@ gNullaryParseJSON2ElemArray = genericParseJSON opts2ElemArray
69gNullaryToJSONTaggedObject :: Nullary -> Value
75gNullaryToJSONTaggedObject :: Nullary -> Value
70gNullaryToJSONTaggedObject = genericToJSON optsTaggedObject
76gNullaryToJSONTaggedObject = genericToJSON optsTaggedObject
71
77
78+gNullaryToEncodingTaggedObject :: Nullary -> Encoding
79+gNullaryToEncodingTaggedObject = genericToEncoding optsTaggedObject
80+
72gNullaryParseJSONTaggedObject :: Value -> Parser Nullary
81gNullaryParseJSONTaggedObject :: Value -> Parser Nullary
73gNullaryParseJSONTaggedObject = genericParseJSON optsTaggedObject
82gNullaryParseJSONTaggedObject = genericParseJSON optsTaggedObject
74
83
@@ -76,6 +85,9 @@ gNullaryParseJSONTaggedObject = genericParseJSON optsTaggedObject
76gNullaryToJSONObjectWithSingleField :: Nullary -> Value
85gNullaryToJSONObjectWithSingleField :: Nullary -> Value
77gNullaryToJSONObjectWithSingleField = genericToJSON optsObjectWithSingleField
86gNullaryToJSONObjectWithSingleField = genericToJSON optsObjectWithSingleField
78
87
88+gNullaryToEncodingObjectWithSingleField :: Nullary -> Encoding
89+gNullaryToEncodingObjectWithSingleField = genericToEncoding optsObjectWithSingleField
90+
79gNullaryParseJSONObjectWithSingleField :: Value -> Parser Nullary
91gNullaryParseJSONObjectWithSingleField :: Value -> Parser Nullary
80gNullaryParseJSONObjectWithSingleField = genericParseJSON optsObjectWithSingleField
92gNullaryParseJSONObjectWithSingleField = genericParseJSON optsObjectWithSingleField
81
93
@@ -120,6 +132,9 @@ thSomeTypeParseJSONObjectWithSingleField =
120gSomeTypeToJSON2ElemArray :: SomeType Int -> Value
132gSomeTypeToJSON2ElemArray :: SomeType Int -> Value
121gSomeTypeToJSON2ElemArray = genericToJSON opts2ElemArray
133gSomeTypeToJSON2ElemArray = genericToJSON opts2ElemArray
122
134
135+gSomeTypeToEncoding2ElemArray :: SomeType Int -> Encoding
136+gSomeTypeToEncoding2ElemArray = genericToEncoding opts2ElemArray
137+
123gSomeTypeParseJSON2ElemArray :: Value -> Parser (SomeType Int)
138gSomeTypeParseJSON2ElemArray :: Value -> Parser (SomeType Int)
124gSomeTypeParseJSON2ElemArray = genericParseJSON opts2ElemArray
139gSomeTypeParseJSON2ElemArray = genericParseJSON opts2ElemArray
125
140
@@ -127,6 +142,9 @@ gSomeTypeParseJSON2ElemArray = genericParseJSON opts2ElemArray
127gSomeTypeToJSONTaggedObject :: SomeType Int -> Value
142gSomeTypeToJSONTaggedObject :: SomeType Int -> Value
128gSomeTypeToJSONTaggedObject = genericToJSON optsTaggedObject
143gSomeTypeToJSONTaggedObject = genericToJSON optsTaggedObject
129
144
145+gSomeTypeToEncodingTaggedObject :: SomeType Int -> Encoding
146+gSomeTypeToEncodingTaggedObject = genericToEncoding optsTaggedObject
147+
130gSomeTypeParseJSONTaggedObject :: Value -> Parser (SomeType Int)
148gSomeTypeParseJSONTaggedObject :: Value -> Parser (SomeType Int)
131gSomeTypeParseJSONTaggedObject = genericParseJSON optsTaggedObject
149gSomeTypeParseJSONTaggedObject = genericParseJSON optsTaggedObject
132
150
@@ -134,6 +152,9 @@ gSomeTypeParseJSONTaggedObject = genericParseJSON optsTaggedObject
134gSomeTypeToJSONObjectWithSingleField :: SomeType Int -> Value
152gSomeTypeToJSONObjectWithSingleField :: SomeType Int -> Value
135gSomeTypeToJSONObjectWithSingleField = genericToJSON optsObjectWithSingleField
153gSomeTypeToJSONObjectWithSingleField = genericToJSON optsObjectWithSingleField
136
154
155+gSomeTypeToEncodingObjectWithSingleField :: SomeType Int -> Encoding
156+gSomeTypeToEncodingObjectWithSingleField = genericToEncoding optsObjectWithSingleField
157+
137gSomeTypeParseJSONObjectWithSingleField :: Value -> Parser (SomeType Int)
158gSomeTypeParseJSONObjectWithSingleField :: Value -> Parser (SomeType Int)
138gSomeTypeParseJSONObjectWithSingleField = genericParseJSON optsObjectWithSingleField
159gSomeTypeParseJSONObjectWithSingleField = genericParseJSON optsObjectWithSingleField
139
160
@@ -164,6 +185,9 @@ thApproxParseJSONDefault = $(mkParseJSON defaultOptions ''Approx)
164gApproxToJSONUnwrap :: Approx String -> Value
185gApproxToJSONUnwrap :: Approx String -> Value
165gApproxToJSONUnwrap = genericToJSON optsUnwrapUnaryRecords
186gApproxToJSONUnwrap = genericToJSON optsUnwrapUnaryRecords
166
187
188+gApproxToEncodingUnwrap :: Approx String -> Encoding
189+gApproxToEncodingUnwrap = genericToEncoding optsUnwrapUnaryRecords
190+
167gApproxParseJSONUnwrap :: Value -> Parser (Approx String)
191gApproxParseJSONUnwrap :: Value -> Parser (Approx String)
168gApproxParseJSONUnwrap = genericParseJSON optsUnwrapUnaryRecords
192gApproxParseJSONUnwrap = genericParseJSON optsUnwrapUnaryRecords
169
193
@@ -171,5 +195,8 @@ gApproxParseJSONUnwrap = genericParseJSON optsUnwrapUnaryRecords
171gApproxToJSONDefault :: Approx String -> Value
195gApproxToJSONDefault :: Approx String -> Value
172gApproxToJSONDefault = genericToJSON defaultOptions
196gApproxToJSONDefault = genericToJSON defaultOptions
173
197
198+gApproxToEncodingDefault :: Approx String -> Encoding
199+gApproxToEncodingDefault = genericToEncoding defaultOptions
200+
174gApproxParseJSONDefault :: Value -> Parser (Approx String)
201gApproxParseJSONDefault :: Value -> Parser (Approx String)
175gApproxParseJSONDefault = genericParseJSON defaultOptions
202gApproxParseJSONDefault = genericParseJSON defaultOptions
tests/Properties.hs+48
@@ -153,6 +153,54 @@ tests = testGroup "properties" [
153 , testGroup "failure messages" [
153 , testGroup "failure messages" [
154 testProperty "modify failure" modifyFailureProp
154 testProperty "modify failure" modifyFailureProp
155 ]
155 ]
156+ , testGroup "generic" [
157+ testGroup "toJSON" [
158+ testGroup "Nullary" [
159+ testProperty "string" (isString . gNullaryToJSONString)
160+ , testProperty "2ElemArray" (is2ElemArray . gNullaryToJSON2ElemArray)
161+ , testProperty "TaggedObject" (isTaggedObject . gNullaryToJSONTaggedObject)
162+ , testProperty "ObjectWithSingleField" (isObjectWithSingleField . gNullaryToJSONObjectWithSingleField)
163+ , testGroup "roundTrip" [
164+ testProperty "string" (toParseJSON gNullaryParseJSONString gNullaryToJSONString)
165+ , testProperty "2ElemArray" (toParseJSON gNullaryParseJSON2ElemArray gNullaryToJSON2ElemArray)
166+ , testProperty "TaggedObject" (toParseJSON gNullaryParseJSONTaggedObject gNullaryToJSONTaggedObject)
167+ , testProperty "ObjectWithSingleField" (toParseJSON gNullaryParseJSONObjectWithSingleField gNullaryToJSONObjectWithSingleField)
168+ ]
169+ ]
170+ , testGroup "SomeType" [
171+ testProperty "2ElemArray" (is2ElemArray . gSomeTypeToJSON2ElemArray)
172+ , testProperty "TaggedObject" (isTaggedObject . gSomeTypeToJSONTaggedObject)
173+ , testProperty "ObjectWithSingleField" (isObjectWithSingleField . gSomeTypeToJSONObjectWithSingleField)
174+ , testGroup "roundTrip" [
175+ testProperty "2ElemArray" (toParseJSON gSomeTypeParseJSON2ElemArray gSomeTypeToJSON2ElemArray)
176+ , testProperty "TaggedObject" (toParseJSON gSomeTypeParseJSONTaggedObject gSomeTypeToJSONTaggedObject)
177+ , testProperty "ObjectWithSingleField" (toParseJSON gSomeTypeParseJSONObjectWithSingleField gSomeTypeToJSONObjectWithSingleField)
178+ ]
179+ ]
180+ ]
181+ , testGroup "toEncoding" [
182+ testProperty "NullaryString" $
183+ gNullaryToJSONString `sameAs` gNullaryToEncodingString
184+ , testProperty "Nullary2ElemArray" $
185+ gNullaryToJSON2ElemArray `sameAs` gNullaryToEncoding2ElemArray
186+ , testProperty "NullaryTaggedObject" $
187+ gNullaryToJSONTaggedObject `sameAs` gNullaryToEncodingTaggedObject
188+ , testProperty "NullaryObjectWithSingleField" $
189+ gNullaryToJSONObjectWithSingleField `sameAs`
190+ gNullaryToEncodingObjectWithSingleField
191+ -- , testProperty "ApproxUnwrap" $
192+ -- gApproxToJSONUnwrap `sameAs` gApproxToEncodingUnwrap
193+ , testProperty "ApproxDefault" $
194+ gApproxToJSONDefault `sameAs` gApproxToEncodingDefault
195+ , testProperty "SomeType2ElemArray" $
196+ gSomeTypeToJSON2ElemArray `sameAsV` gSomeTypeToEncoding2ElemArray
197+ , testProperty "SomeTypeTaggedObject" $
198+ gSomeTypeToJSONTaggedObject `sameAsV` gSomeTypeToEncodingTaggedObject
199+ , testProperty "SomeTypeObjectWithSingleField" $
200+ gSomeTypeToJSONObjectWithSingleField `sameAsV`
201+ gSomeTypeToEncodingObjectWithSingleField
202+ ]
203+ ]
156 , testGroup "template-haskell" [
204 , testGroup "template-haskell" [
157 testGroup "toJSON" [
205 testGroup "toJSON" [
158 testGroup "Nullary" [
206 testGroup "Nullary" [