Skip to content

Commit 66d68f5

Browse files
committed
add regression test for #1059
1 parent c1f6c14 commit 66d68f5

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

aeson.cabal

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,7 @@ test-suite aeson-tests
175175
Regression.Issue571
176176
Regression.Issue687
177177
Regression.Issue967
178+
Regression.Issue1059
178179
RFC8785
179180
SerializationFormatSpec
180181
Types

tests/Regression/Issue1059.hs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{-# LANGUAGE OverloadedStrings #-}
2+
{-# LANGUAGE DeriveFunctor #-}
3+
{-# LANGUAGE DeriveGeneric #-}
4+
{-# LANGUAGE StandaloneDeriving #-}
5+
{-# LANGUAGE UndecidableInstances #-}
6+
7+
module Regression.Issue1059 (issue1059) where
8+
9+
import GHC.Generics
10+
import Data.Aeson
11+
import Test.Tasty
12+
import Test.Tasty.HUnit
13+
14+
data Item f a = Item { rec0 :: Int, par1 :: a, rec1 :: f a, comp1 :: f (f a) } deriving (Functor, Generic1)
15+
16+
deriving instance (Eq a, Eq (f a), Eq (f (f a))) => Eq (Item f a)
17+
deriving instance (Show a, Show (f a), Show (f (f a))) => Show (Item f a)
18+
19+
instance (Functor f, FromJSON1 f) => FromJSON1 (Item f) where
20+
liftParseJSON = genericLiftParseJSON $ defaultOptions { allowOmittedFields = True }
21+
instance (Functor f, ToJSON1 f) => ToJSON1 (Item f) where
22+
liftToJSON = genericLiftToJSON $ defaultOptions { omitNothingFields = True }
23+
instance (Functor f, FromJSON1 f, FromJSON a) => FromJSON (Item f a) where parseJSON = parseJSON1
24+
instance (Functor f, ToJSON1 f, ToJSON a) => ToJSON (Item f a) where toJSON = toJSON1
25+
26+
data Test a = Test { a :: Item [] (Maybe a), b :: Item Maybe a } deriving (Eq, Show, Generic1)
27+
28+
instance FromJSON1 Test where liftParseJSON = genericLiftParseJSON defaultOptions
29+
instance ToJSON1 Test where liftToJSON = genericLiftToJSON defaultOptions
30+
instance FromJSON a => FromJSON (Test a) where parseJSON = parseJSON1
31+
instance ToJSON a => ToJSON (Test a) where toJSON = toJSON1
32+
33+
issue1059 :: TestTree
34+
issue1059 = testCase "issue1059" $ do
35+
let value = Test (Item 0 Nothing [] []) (Item 0 1 Nothing Nothing) :: Test Int
36+
let code = "{\"a\":{\"comp1\":[],\"rec0\":0,\"rec1\":[]},\"b\":{\"par1\":1,\"rec0\":0}}"
37+
encode value @?= code
38+
decode code @?= Just value

tests/UnitTests.hs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ import Regression.Issue351
6464
import Regression.Issue571
6565
import Regression.Issue687
6666
import Regression.Issue967
67+
import Regression.Issue1059
6768
import UnitTests.OmitNothingFieldsNote
6869
import UnitTests.FromJSONKey
6970
import UnitTests.Hashable
@@ -568,6 +569,7 @@ tests = testGroup "unit" [
568569
, issue571
569570
, issue687
570571
, issue967
572+
, issue1059
571573
, keyMapInsertWithTests
572574
, omitNothingFieldsNoteTests
573575
, noThunksTests

0 commit comments

Comments
 (0)