aboutsummaryrefslogtreecommitdiff
path: root/tests/Language/GraphQL/AST/ParserSpec.hs
diff options
context:
space:
mode:
Diffstat (limited to 'tests/Language/GraphQL/AST/ParserSpec.hs')
-rw-r--r--tests/Language/GraphQL/AST/ParserSpec.hs105
1 files changed, 67 insertions, 38 deletions
diff --git a/tests/Language/GraphQL/AST/ParserSpec.hs b/tests/Language/GraphQL/AST/ParserSpec.hs
index 702beab..13faa21 100644
--- a/tests/Language/GraphQL/AST/ParserSpec.hs
+++ b/tests/Language/GraphQL/AST/ParserSpec.hs
@@ -5,46 +5,78 @@ module Language.GraphQL.AST.ParserSpec
) where
import Data.List.NonEmpty (NonEmpty(..))
+import Data.Text (Text)
+import qualified Data.Text as Text
import Language.GraphQL.AST.Document
import qualified Language.GraphQL.AST.DirectiveLocation as DirLoc
import Language.GraphQL.AST.Parser
import Language.GraphQL.TH
-import Test.Hspec (Spec, describe, it)
+import Test.Hspec (Spec, describe, it, context)
import Test.Hspec.Megaparsec (shouldParse, shouldFailOn, shouldSucceedOn)
import Text.Megaparsec (parse)
+import Test.QuickCheck (property, NonEmptyList (..), mapSize)
+import Language.GraphQL.AST.Arbitrary
spec :: Spec
spec = describe "Parser" $ do
it "accepts BOM header" $
parse document "" `shouldSucceedOn` "\xfeff{foo}"
- it "accepts block strings as argument" $
- parse document "" `shouldSucceedOn` [gql|{
- hello(text: """Argument""")
- }|]
-
- it "accepts strings as argument" $
- parse document "" `shouldSucceedOn` [gql|{
- hello(text: "Argument")
- }|]
-
- it "accepts two required arguments" $
- parse document "" `shouldSucceedOn` [gql|
- mutation auth($username: String!, $password: String!){
- test
- }|]
-
- it "accepts two string arguments" $
- parse document "" `shouldSucceedOn` [gql|
- mutation auth{
- test(username: "username", password: "password")
- }|]
-
- it "accepts two block string arguments" $
- parse document "" `shouldSucceedOn` [gql|
- mutation auth{
- test(username: """username""", password: """password""")
- }|]
+ context "Arguments" $ do
+ it "accepts block strings as argument" $
+ parse document "" `shouldSucceedOn` [gql|{
+ hello(text: """Argument""")
+ }|]
+
+ it "accepts strings as argument" $
+ parse document "" `shouldSucceedOn` [gql|{
+ hello(text: "Argument")
+ }|]
+
+ it "accepts int as argument1" $
+ parse document "" `shouldSucceedOn` [gql|{
+ user(id: 4)
+ }|]
+
+ it "accepts boolean as argument" $
+ parse document "" `shouldSucceedOn` [gql|{
+ hello(flag: true) { field1 }
+ }|]
+
+ it "accepts float as argument" $
+ parse document "" `shouldSucceedOn` [gql|{
+ body(height: 172.5) { height }
+ }|]
+
+ it "accepts empty list as argument" $
+ parse document "" `shouldSucceedOn` [gql|{
+ query(list: []) { field1 }
+ }|]
+
+ it "accepts two required arguments" $
+ parse document "" `shouldSucceedOn` [gql|
+ mutation auth($username: String!, $password: String!){
+ test
+ }|]
+
+ it "accepts two string arguments" $
+ parse document "" `shouldSucceedOn` [gql|
+ mutation auth{
+ test(username: "username", password: "password")
+ }|]
+
+ it "accepts two block string arguments" $
+ parse document "" `shouldSucceedOn` [gql|
+ mutation auth{
+ test(username: """username""", password: """password""")
+ }|]
+
+ it "accepts any arguments" $ mapSize (const 10) $ property $ \xs ->
+ let
+ query' :: Text
+ arguments = map printArgument $ getNonEmpty (xs :: NonEmptyList (AnyArgument AnyValue))
+ query' = "query(" <> Text.intercalate ", " arguments <> ")" in
+ parse document "" `shouldSucceedOn` ("{ " <> query' <> " }")
it "parses minimal schema definition" $
parse document "" `shouldSucceedOn` [gql|schema { query: Query }|]
@@ -95,16 +127,6 @@ spec = describe "Parser" $ do
}
|]
- it "parses minimal enum type definition" $
- parse document "" `shouldSucceedOn` [gql|
- enum Direction {
- NORTH
- EAST
- SOUTH
- WEST
- }
- |]
-
it "parses minimal input object type definition" $
parse document "" `shouldSucceedOn` [gql|
input Point2D {
@@ -202,6 +224,13 @@ spec = describe "Parser" $ do
}
|]
+ it "rejects empty selection set" $
+ parse document "" `shouldFailOn` [gql|
+ query {
+ innerField {}
+ }
+ |]
+
it "parses documents beginning with a comment" $
parse document "" `shouldSucceedOn` [gql|
"""