Skip to content

Commit 00d839a

Browse files
committed
Add regression test for #627
1 parent 8b007a8 commit 00d839a

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

tests/UnitTests.hs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ tests = testGroup "unit" [
9999
, testCase "Show Options" showOptions
100100
, testGroup "SingleMaybeField" singleMaybeField
101101
, testCase "withEmbeddedJSON" withEmbeddedJSONTest
102+
, testCase "SingleFieldCon" singleFieldCon
102103
]
103104

104105
roundTripCamel :: String -> Assertion
@@ -534,6 +535,17 @@ withEmbeddedJSONTest :: Assertion
534535
withEmbeddedJSONTest =
535536
assertEqual "Unquote embedded JSON" (Right $ EmbeddedJSONTest 1) (eitherDecode "{\"prop\":\"1\"}")
536537

538+
-- Regression test for https://github.com/bos/aeson/issues/627
539+
newtype SingleFieldCon = SingleFieldCon Int deriving (Eq, Show, Generic)
540+
541+
instance FromJSON SingleFieldCon where
542+
parseJSON = genericParseJSON defaultOptions{unwrapUnaryRecords=True}
543+
-- This option should have no effect on this type
544+
545+
singleFieldCon :: Assertion
546+
singleFieldCon =
547+
assertEqual "fromJSON" (Right (SingleFieldCon 0)) (eitherDecode "0")
548+
537549
deriveJSON defaultOptions{omitNothingFields=True} ''MyRecord
538550

539551
deriveToJSON defaultOptions ''Foo

0 commit comments

Comments
 (0)