Skip to content

Commit 5f5f92c

Browse files
committed
Add test for generic deriving fromValue fix
1 parent f7ed7bb commit 5f5f92c

File tree

1 file changed

+22
-1
lines changed

1 file changed

+22
-1
lines changed

tests/ValueTests.hs

+22-1
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
{-# LANGUAGE DeriveGeneric #-}
12
module ValueTests (tests) where
23

34
import Protolude
@@ -11,15 +12,24 @@ import qualified GraphQL.Internal.Syntax.AST as AST
1112
import GraphQL.Internal.Arbitrary (arbitraryText, arbitraryNonEmpty)
1213
import GraphQL.Value
1314
( Object
15+
, Value'(ValueObject')
1416
, ObjectField'(..)
1517
, astToVariableValue
1618
, unionObjects
1719
, objectFields
1820
, objectFromList
1921
, toValue
2022
)
21-
import GraphQL.Internal.Value.FromValue (prop_roundtripValue)
23+
import GraphQL.Internal.Value.FromValue (FromValue(..), prop_roundtripValue)
2224

25+
data Resource = Resource
26+
{ resText :: Text
27+
, resInt :: Int32
28+
, resDouble :: Double
29+
, resBool :: Bool
30+
} deriving (Generic, Eq, Show)
31+
32+
instance FromValue Resource
2333

2434
tests :: IO TestTree
2535
tests = testSpec "Value" $ do
@@ -47,6 +57,17 @@ tests = testSpec "Value" $ do
4757
describe "Objects" $ do
4858
prop "have unique fields" $ do
4959
prop_fieldsUnique
60+
-- See https://github.com/haskell-graphql/graphql-api/pull/178 for background
61+
it "derives fromValue instances for objects with more than three fields" $ do
62+
let Just value = objectFromList
63+
[ ("resText", toValue @Text "text")
64+
, ("resBool", toValue @Bool False)
65+
, ("resDouble", toValue @Double 1.2)
66+
, ("resInt", toValue @Int32 32)
67+
]
68+
let Right observed = fromValue $ ValueObject' value
69+
observed `shouldBe` Resource "text" 32 1.2 False
70+
5071
describe "ToValue / FromValue instances" $ do
5172
prop "Bool" $ prop_roundtripValue @Bool
5273
prop "Int32" $ prop_roundtripValue @Int32

0 commit comments

Comments
 (0)