on master help sign in
Added tests/Options.hs
c595a42Bas van Dijk
tests/Options.hsnew file+24
@@ -0,0 +1,24 @@
1+module Options where
2+
3+import Data.Aeson.Types
4+import Data.Char
5+
6+optsDefault :: Options
7+optsDefault = defaultOptions{ fieldNameModifier = map toLower
8+ , constructorNameModifier = map toLower
9+ }
10+
11+opts2ElemArray :: Options
12+opts2ElemArray = optsDefault{ nullaryToString = False }
13+
14+optsObjectWithType :: Options
15+optsObjectWithType = optsDefault
16+ { nullaryToString = False
17+ , sumEncoding = defaultObjectWithType
18+ }
19+
20+optsObjectWithSingleField :: Options
21+optsObjectWithSingleField = optsDefault
22+ { nullaryToString = False
23+ , sumEncoding = ObjectWithSingleField
24+ }
tests/Properties.hs+4−4
@@ -125,10 +125,10 @@ instance Arbitrary Nullary where
125 arbitrary = elements [C1, C2, C3]
125 arbitrary = elements [C1, C2, C3]
126
126
127thNullaryToJSONString :: Nullary -> Value
127thNullaryToJSONString :: Nullary -> Value
128−thNullaryToJSONString = $(mkToJSON defaultOptions ''Nullary)
128+thNullaryToJSONString = $(mkToJSON optsDefault ''Nullary)
129
129
130thNullaryParseJSONString :: Value -> Parser Nullary
130thNullaryParseJSONString :: Value -> Parser Nullary
131−thNullaryParseJSONString = $(mkParseJSON defaultOptions ''Nullary)
131+thNullaryParseJSONString = $(mkParseJSON optsDefault ''Nullary)
132
132
133
133
134thNullaryToJSON2ElemArray :: Nullary -> Value
134thNullaryToJSON2ElemArray :: Nullary -> Value
@@ -155,10 +155,10 @@ thNullaryParseJSONObjectWithSingleField = $(mkParseJSON optsObjectWithSingleFiel
155deriving instance Generic Nullary
155deriving instance Generic Nullary
156
156
157gNullaryToJSONString :: Nullary -> Value
157gNullaryToJSONString :: Nullary -> Value
158−gNullaryToJSONString = gToJSON defaultOptions . from
158+gNullaryToJSONString = gToJSON optsDefault . from
159
159
160gNullaryParseJSONString :: Value -> Parser Nullary
160gNullaryParseJSONString :: Value -> Parser Nullary
161−gNullaryParseJSONString = fmap to . gParseJSON defaultOptions
161+gNullaryParseJSONString = fmap to . gParseJSON optsDefault
162
162
163
163
164gNullaryToJSON2ElemArray :: Nullary -> Value
164gNullaryToJSON2ElemArray :: Nullary -> Value