on master help sign in
Another TH test, and a bug fix
commit9728e9a570501b71fdafe6b5e4a2ac9f3192f68f authorBryan O'Sullivan <bos@serpentine.com> dateThu 2 Jul 2015, 15:19 (11 years ago) parent30834b5
3 files changed+9−3
Data/Aeson/TH.hs+4−3 tests/Encoders.hs+3 tests/Properties.hs+2
Data/Aeson/TH.hs+4−3
@@ -429,15 +429,16 @@ object exp = [|Encoding|] `appE` ([|E.char7 '{'|] <^> exp <^> [|E.char7 '}'|])
429429sumToEncoding :: Options -> Bool -> Name -> Q Exp -> Q Exp
430430sumToEncoding opts multiCons conName exp
431431 | multiCons =
432+ let fexp = [|fromEncoding|] `appE` exp in
432433 case sumEncoding opts of
433434 TwoElemArray ->
434− array (encStr opts conName <%> exp)
435+ array (encStr opts conName <%> fexp)
435436 TaggedObject{tagFieldName, contentsFieldName} ->
436437 object $
437438 ([|E.builder tagFieldName|] <:> encStr opts conName) <%>
438− ([|E.builder contentsFieldName|] <:> [|fromEncoding|] `appE` exp)
439+ ([|E.builder contentsFieldName|] <:> fexp)
439440 ObjectWithSingleField ->
440− object (conTxt opts conName <:> [|fromEncoding|] `appE` exp)
441+ object (conTxt opts conName <:> fexp)
441442
442443 | otherwise = exp
443444
tests/Encoders.hs+3
@@ -24,6 +24,9 @@ thNullaryParseJSONString = $(mkParseJSON defaultOptions ''Nullary)
2424thNullaryToJSON2ElemArray :: Nullary -> Value
2525thNullaryToJSON2ElemArray = $(mkToJSON opts2ElemArray ''Nullary)
2626
27+thNullaryToEncoding2ElemArray :: Nullary -> Encoding
28+thNullaryToEncoding2ElemArray = $(mkToEncoding opts2ElemArray ''Nullary)
29+
2730thNullaryParseJSON2ElemArray :: Value -> Parser Nullary
2831thNullaryParseJSON2ElemArray = $(mkParseJSON opts2ElemArray ''Nullary)
2932
tests/Properties.hs+2
@@ -194,6 +194,8 @@ tests = [
194194 , testGroup "toEncoding" [
195195 testProperty "NullaryString" $
196196 thNullaryToJSONString `sameAs` thNullaryToEncodingString
197+ , testProperty "Nullary2ElemArray" $
198+ thNullaryToJSON2ElemArray `sameAs` thNullaryToEncoding2ElemArray
197199 ]
198200 ]
199201 ]