on master help sign in
Fix test-suite to use the new encoding Options terminology
commit9f9df01b2b5fe07cb23287a33e4a65cb850a9356 authorBas van Dijk <v.dijk.bas@gmail.com> dateTue 23 Apr 2013, 01:51 (13 years ago) parent4d45258
3 files changed+41−41
tests/Encoders.hs+16−16 tests/Options.hs+8−8 tests/Properties.hs+17−17
tests/Encoders.hs+16−16
@@ -25,11 +25,11 @@ thNullaryParseJSON2ElemArray :: Value -> Parser Nullary
2525thNullaryParseJSON2ElemArray = $(mkParseJSON opts2ElemArray ''Nullary)
2626
2727
28−thNullaryToJSONObjectWithType :: Nullary -> Value
29−thNullaryToJSONObjectWithType = $(mkToJSON optsObjectWithType ''Nullary)
28+thNullaryToJSONTaggedObject :: Nullary -> Value
29+thNullaryToJSONTaggedObject = $(mkToJSON optsTaggedObject ''Nullary)
3030
31−thNullaryParseJSONObjectWithType :: Value -> Parser Nullary
32−thNullaryParseJSONObjectWithType = $(mkParseJSON optsObjectWithType ''Nullary)
31+thNullaryParseJSONTaggedObject :: Value -> Parser Nullary
32+thNullaryParseJSONTaggedObject = $(mkParseJSON optsTaggedObject ''Nullary)
3333
3434
3535thNullaryToJSONObjectWithSingleField :: Nullary -> Value
@@ -52,11 +52,11 @@ gNullaryParseJSON2ElemArray :: Value -> Parser Nullary
5252gNullaryParseJSON2ElemArray = genericParseJSON opts2ElemArray
5353
5454
55−gNullaryToJSONObjectWithType :: Nullary -> Value
56−gNullaryToJSONObjectWithType = genericToJSON optsObjectWithType
55+gNullaryToJSONTaggedObject :: Nullary -> Value
56+gNullaryToJSONTaggedObject = genericToJSON optsTaggedObject
5757
58−gNullaryParseJSONObjectWithType :: Value -> Parser Nullary
59−gNullaryParseJSONObjectWithType = genericParseJSON optsObjectWithType
58+gNullaryParseJSONTaggedObject :: Value -> Parser Nullary
59+gNullaryParseJSONTaggedObject = genericParseJSON optsTaggedObject
6060
6161
6262gNullaryToJSONObjectWithSingleField :: Nullary -> Value
@@ -79,11 +79,11 @@ thSomeTypeParseJSON2ElemArray :: FromJSON a => Value -> Parser (SomeType a)
7979thSomeTypeParseJSON2ElemArray = $(mkParseJSON opts2ElemArray ''SomeType)
8080
8181
82−thSomeTypeToJSONObjectWithType :: ToJSON a => SomeType a -> Value
83−thSomeTypeToJSONObjectWithType = $(mkToJSON optsObjectWithType ''SomeType)
82+thSomeTypeToJSONTaggedObject :: ToJSON a => SomeType a -> Value
83+thSomeTypeToJSONTaggedObject = $(mkToJSON optsTaggedObject ''SomeType)
8484
85−thSomeTypeParseJSONObjectWithType :: FromJSON a => Value -> Parser (SomeType a)
86−thSomeTypeParseJSONObjectWithType = $(mkParseJSON optsObjectWithType ''SomeType)
85+thSomeTypeParseJSONTaggedObject :: FromJSON a => Value -> Parser (SomeType a)
86+thSomeTypeParseJSONTaggedObject = $(mkParseJSON optsTaggedObject ''SomeType)
8787
8888
8989thSomeTypeToJSONObjectWithSingleField :: ToJSON a => SomeType a -> Value
@@ -100,11 +100,11 @@ gSomeTypeParseJSON2ElemArray :: FromJSON a => Value -> Parser (SomeType a)
100100gSomeTypeParseJSON2ElemArray = genericParseJSON opts2ElemArray
101101
102102
103−gSomeTypeToJSONObjectWithType :: ToJSON a => SomeType a -> Value
104−gSomeTypeToJSONObjectWithType = genericToJSON optsObjectWithType
103+gSomeTypeToJSONTaggedObject :: ToJSON a => SomeType a -> Value
104+gSomeTypeToJSONTaggedObject = genericToJSON optsTaggedObject
105105
106−gSomeTypeParseJSONObjectWithType :: FromJSON a => Value -> Parser (SomeType a)
107−gSomeTypeParseJSONObjectWithType = genericParseJSON optsObjectWithType
106+gSomeTypeParseJSONTaggedObject :: FromJSON a => Value -> Parser (SomeType a)
107+gSomeTypeParseJSONTaggedObject = genericParseJSON optsTaggedObject
108108
109109
110110gSomeTypeToJSONObjectWithSingleField :: ToJSON a => SomeType a -> Value
tests/Options.hs+8−8
@@ -5,22 +5,22 @@ import Data.Char
55
66optsDefault :: Options
77optsDefault = defaultOptions
8− { fieldNameModifier = map toLower
9− , constructorNameModifier = map toLower
8+ { fieldLabelModifier = map toLower
9+ , constructorTagModifier = map toLower
1010 }
1111
1212opts2ElemArray :: Options
1313opts2ElemArray = optsDefault
14− { nullaryToString = False
14+ { allNullaryToStringTag = False
1515 , sumEncoding = TwoElemArray
1616 }
1717
18−optsObjectWithType :: Options
19−optsObjectWithType = optsDefault
20− { nullaryToString = False }
18+optsTaggedObject :: Options
19+optsTaggedObject = optsDefault
20+ { allNullaryToStringTag = False }
2121
2222optsObjectWithSingleField :: Options
2323optsObjectWithSingleField = optsDefault
24− { nullaryToString = False
25− , sumEncoding = ObjectWithSingleField
24+ { allNullaryToStringTag = False
25+ , sumEncoding = ObjectWithSingleField
2626 }
tests/Properties.hs+17−17
@@ -94,14 +94,14 @@ is2ElemArray :: Value -> Bool
9494is2ElemArray (Array v) = V.length v == 2 && isString (V.head v)
9595is2ElemArray _ = False
9696
97−isObjectWithTypeValue :: Value -> Bool
98−isObjectWithTypeValue (Object obj) = "type" `H.member` obj &&
99− "value" `H.member` obj
100−isObjectWithTypeValue _ = False
97+isTaggedObjectValue :: Value -> Bool
98+isTaggedObjectValue (Object obj) = "tag" `H.member` obj &&
99+ "contents" `H.member` obj
100+isTaggedObjectValue _ = False
101101
102−isObjectWithType :: Value -> Bool
103−isObjectWithType (Object obj) = "type" `H.member` obj
104−isObjectWithType _ = False
102+isTaggedObject :: Value -> Bool
103+isTaggedObject (Object obj) = "tag" `H.member` obj
104+isTaggedObject _ = False
105105
106106isObjectWithSingleField :: Value -> Bool
107107isObjectWithSingleField (Object obj) = H.size obj == 1
@@ -167,24 +167,24 @@ tests = [
167167 testGroup "Nullary" [
168168 testProperty "string" (isString . thNullaryToJSONString)
169169 , testProperty "2ElemArray" (is2ElemArray . thNullaryToJSON2ElemArray)
170− , testProperty "ObjectWithType" (isObjectWithTypeValue . thNullaryToJSONObjectWithType)
170+ , testProperty "TaggedObject" (isTaggedObjectValue . thNullaryToJSONTaggedObject)
171171 , testProperty "ObjectWithSingleField" (isObjectWithSingleField . thNullaryToJSONObjectWithSingleField)
172172
173173 , testGroup "roundTrip" [
174174 testProperty "string" (toParseJSON thNullaryParseJSONString thNullaryToJSONString)
175175 , testProperty "2ElemArray" (toParseJSON thNullaryParseJSON2ElemArray thNullaryToJSON2ElemArray)
176− , testProperty "ObjectWithType" (toParseJSON thNullaryParseJSONObjectWithType thNullaryToJSONObjectWithType)
176+ , testProperty "TaggedObject" (toParseJSON thNullaryParseJSONTaggedObject thNullaryToJSONTaggedObject)
177177 , testProperty "ObjectWithSingleField" (toParseJSON thNullaryParseJSONObjectWithSingleField thNullaryToJSONObjectWithSingleField)
178178 ]
179179 ]
180180 , testGroup "SomeType" [
181181 testProperty "2ElemArray" (is2ElemArray . (thSomeTypeToJSON2ElemArray :: SomeTypeToJSON))
182− , testProperty "ObjectWithType" (isObjectWithType . (thSomeTypeToJSONObjectWithType :: SomeTypeToJSON))
182+ , testProperty "TaggedObject" (isTaggedObject . (thSomeTypeToJSONTaggedObject :: SomeTypeToJSON))
183183 , testProperty "ObjectWithSingleField" (isObjectWithSingleField . (thSomeTypeToJSONObjectWithSingleField :: SomeTypeToJSON))
184184
185185 , testGroup "roundTrip" [
186186 testProperty "2ElemArray" (toParseJSON thSomeTypeParseJSON2ElemArray (thSomeTypeToJSON2ElemArray :: SomeTypeToJSON))
187− , testProperty "ObjectWithType" (toParseJSON thSomeTypeParseJSONObjectWithType (thSomeTypeToJSONObjectWithType :: SomeTypeToJSON))
187+ , testProperty "TaggedObject" (toParseJSON thSomeTypeParseJSONTaggedObject (thSomeTypeToJSONTaggedObject :: SomeTypeToJSON))
188188 , testProperty "ObjectWithSingleField" (toParseJSON thSomeTypeParseJSONObjectWithSingleField (thSomeTypeToJSONObjectWithSingleField :: SomeTypeToJSON))
189189 ]
190190 ]
@@ -193,34 +193,34 @@ tests = [
193193 testGroup "Nullary" [
194194 testProperty "string" (isString . gNullaryToJSONString)
195195 , testProperty "2ElemArray" (is2ElemArray . gNullaryToJSON2ElemArray)
196− , testProperty "ObjectWithType" (isObjectWithTypeValue . gNullaryToJSONObjectWithType)
196+ , testProperty "TaggedObject" (isTaggedObjectValue . gNullaryToJSONTaggedObject)
197197 , testProperty "ObjectWithSingleField" (isObjectWithSingleField . gNullaryToJSONObjectWithSingleField)
198198 , testGroup "eq" [
199199 testProperty "string" (\n -> gNullaryToJSONString n == thNullaryToJSONString n)
200200 , testProperty "2ElemArray" (\n -> gNullaryToJSON2ElemArray n == thNullaryToJSON2ElemArray n)
201− , testProperty "ObjectWithType" (\n -> gNullaryToJSONObjectWithType n == thNullaryToJSONObjectWithType n)
201+ , testProperty "TaggedObject" (\n -> gNullaryToJSONTaggedObject n == thNullaryToJSONTaggedObject n)
202202 , testProperty "ObjectWithSingleField" (\n -> gNullaryToJSONObjectWithSingleField n == thNullaryToJSONObjectWithSingleField n)
203203 ]
204204 , testGroup "roundTrip" [
205205 testProperty "string" (toParseJSON gNullaryParseJSONString gNullaryToJSONString)
206206 , testProperty "2ElemArray" (toParseJSON gNullaryParseJSON2ElemArray gNullaryToJSON2ElemArray)
207− , testProperty "ObjectWithType" (toParseJSON gNullaryParseJSONObjectWithType gNullaryToJSONObjectWithType)
207+ , testProperty "TaggedObject" (toParseJSON gNullaryParseJSONTaggedObject gNullaryToJSONTaggedObject)
208208 , testProperty "ObjectWithSingleField" (toParseJSON gNullaryParseJSONObjectWithSingleField gNullaryToJSONObjectWithSingleField)
209209 ]
210210 ]
211211 , testGroup "SomeType" [
212212 testProperty "2ElemArray" (is2ElemArray . (gSomeTypeToJSON2ElemArray :: SomeTypeToJSON))
213− , testProperty "ObjectWithType" (isObjectWithType . (gSomeTypeToJSONObjectWithType :: SomeTypeToJSON))
213+ , testProperty "TaggedObject" (isTaggedObject . (gSomeTypeToJSONTaggedObject :: SomeTypeToJSON))
214214 , testProperty "ObjectWithSingleField" (isObjectWithSingleField . (gSomeTypeToJSONObjectWithSingleField :: SomeTypeToJSON))
215215
216216 , testGroup "eq" [
217217 testProperty "2ElemArray" (\n -> (gSomeTypeToJSON2ElemArray :: SomeTypeToJSON) n == thSomeTypeToJSON2ElemArray n)
218− , testProperty "ObjectWithType" (\n -> (gSomeTypeToJSONObjectWithType :: SomeTypeToJSON) n == thSomeTypeToJSONObjectWithType n)
218+ , testProperty "TaggedObject" (\n -> (gSomeTypeToJSONTaggedObject :: SomeTypeToJSON) n == thSomeTypeToJSONTaggedObject n)
219219 , testProperty "ObjectWithSingleField" (\n -> (gSomeTypeToJSONObjectWithSingleField :: SomeTypeToJSON) n == thSomeTypeToJSONObjectWithSingleField n)
220220 ]
221221 , testGroup "roundTrip" [
222222 testProperty "2ElemArray" (toParseJSON gSomeTypeParseJSON2ElemArray (gSomeTypeToJSON2ElemArray :: SomeTypeToJSON))
223− , testProperty "ObjectWithType" (toParseJSON gSomeTypeParseJSONObjectWithType (gSomeTypeToJSONObjectWithType :: SomeTypeToJSON))
223+ , testProperty "TaggedObject" (toParseJSON gSomeTypeParseJSONTaggedObject (gSomeTypeToJSONTaggedObject :: SomeTypeToJSON))
224224 , testProperty "ObjectWithSingleField" (toParseJSON gSomeTypeParseJSONObjectWithSingleField (gSomeTypeToJSONObjectWithSingleField :: SomeTypeToJSON))
225225 ]
226226 ]