on master help sign in
Another TH test, and a bug fix
9728e9aBryan O'Sullivan
Data/Aeson/TH.hs+4−3
@@ -429,15 +429,16 @@ object exp = [|Encoding|] `appE` ([|E.char7 '{'|] <^> exp <^> [|E.char7 '}'|])
429sumToEncoding :: Options -> Bool -> Name -> Q Exp -> Q Exp
429sumToEncoding :: Options -> Bool -> Name -> Q Exp -> Q Exp
430sumToEncoding opts multiCons conName exp
430sumToEncoding opts multiCons conName exp
431 | multiCons =
431 | multiCons =
432+ let fexp = [|fromEncoding|] `appE` exp in
432 case sumEncoding opts of
433 case sumEncoding opts of
433 TwoElemArray ->
434 TwoElemArray ->
434− array (encStr opts conName <%> exp)
435+ array (encStr opts conName <%> fexp)
435 TaggedObject{tagFieldName, contentsFieldName} ->
436 TaggedObject{tagFieldName, contentsFieldName} ->
436 object $
437 object $
437 ([|E.builder tagFieldName|] <:> encStr opts conName) <%>
438 ([|E.builder tagFieldName|] <:> encStr opts conName) <%>
438− ([|E.builder contentsFieldName|] <:> [|fromEncoding|] `appE` exp)
439+ ([|E.builder contentsFieldName|] <:> fexp)
439 ObjectWithSingleField ->
440 ObjectWithSingleField ->
440− object (conTxt opts conName <:> [|fromEncoding|] `appE` exp)
441+ object (conTxt opts conName <:> fexp)
441
442
442 | otherwise = exp
443 | otherwise = exp
443
444
tests/Encoders.hs+3
@@ -24,6 +24,9 @@ thNullaryParseJSONString = $(mkParseJSON defaultOptions ''Nullary)
24thNullaryToJSON2ElemArray :: Nullary -> Value
24thNullaryToJSON2ElemArray :: Nullary -> Value
25thNullaryToJSON2ElemArray = $(mkToJSON opts2ElemArray ''Nullary)
25thNullaryToJSON2ElemArray = $(mkToJSON opts2ElemArray ''Nullary)
26
26
27+thNullaryToEncoding2ElemArray :: Nullary -> Encoding
28+thNullaryToEncoding2ElemArray = $(mkToEncoding opts2ElemArray ''Nullary)
29+
27thNullaryParseJSON2ElemArray :: Value -> Parser Nullary
30thNullaryParseJSON2ElemArray :: Value -> Parser Nullary
28thNullaryParseJSON2ElemArray = $(mkParseJSON opts2ElemArray ''Nullary)
31thNullaryParseJSON2ElemArray = $(mkParseJSON opts2ElemArray ''Nullary)
29
32
tests/Properties.hs+2
@@ -194,6 +194,8 @@ tests = [
194 , testGroup "toEncoding" [
194 , testGroup "toEncoding" [
195 testProperty "NullaryString" $
195 testProperty "NullaryString" $
196 thNullaryToJSONString `sameAs` thNullaryToEncodingString
196 thNullaryToJSONString `sameAs` thNullaryToEncodingString
197+ , testProperty "Nullary2ElemArray" $
198+ thNullaryToJSON2ElemArray `sameAs` thNullaryToEncoding2ElemArray
197 ]
199 ]
198 ]
200 ]
199 ]
201 ]