diff options
Diffstat (limited to 'tests/Language/GraphQL')
| -rw-r--r-- | tests/Language/GraphQL/AST/EncoderSpec.hs | 49 | ||||
| -rw-r--r-- | tests/Language/GraphQL/AST/ParserSpec.hs | 12 |
2 files changed, 50 insertions, 11 deletions
diff --git a/tests/Language/GraphQL/AST/EncoderSpec.hs b/tests/Language/GraphQL/AST/EncoderSpec.hs index a418a61..0067c83 100644 --- a/tests/Language/GraphQL/AST/EncoderSpec.hs +++ b/tests/Language/GraphQL/AST/EncoderSpec.hs @@ -1,19 +1,46 @@ {-# LANGUAGE OverloadedStrings #-} +{-# LANGUAGE QuasiQuotes #-} module Language.GraphQL.AST.EncoderSpec ( spec ) where -import Language.GraphQL.AST (Value(..)) +import Language.GraphQL.AST import Language.GraphQL.AST.Encoder -import Test.Hspec ( Spec - , describe - , it - , shouldBe - ) +import Test.Hspec (Spec, context, describe, it, shouldBe) +import Text.RawString.QQ (r) spec :: Spec -spec = describe "value" $ do - it "escapes \\" $ - value minified (String "\\") `shouldBe` "\"\\\\\"" - it "escapes quotes" $ - value minified (String "\"") `shouldBe` "\"\\\"\"" +spec = do + describe "value" $ do + context "minified" $ do + it "escapes \\" $ + value minified (String "\\") `shouldBe` "\"\\\\\"" + it "escapes quotes" $ + value minified (String "\"") `shouldBe` "\"\\\"\"" + it "escapes backspace" $ + value minified (String "a\bc") `shouldBe` "\"a\\bc\"" + it "escapes Unicode" $ + value minified (String "\0") `shouldBe` "\"\\u0000\"" + + context "pretty" $ do + it "uses strings for short string values" $ + value pretty (String "Short text") `shouldBe` "\"Short text\"" + it "uses block strings for text with new lines" $ + value pretty (String "Line 1\nLine 2") + `shouldBe` "\"\"\"\n Line 1\n Line 2\n\"\"\"" + it "escapes \\ in short strings" $ + value pretty (String "\\") `shouldBe` "\"\\\\\"" + + describe "definition" $ + it "indents block strings in arguments" $ + let arguments = [Argument "message" (String "line1\nline2")] + field = Field Nothing "field" arguments [] [] + set = OperationSelectionSet $ pure $ SelectionField field + operation = DefinitionOperation set + in definition pretty operation `shouldBe` [r|{ + field(message: """ + line1 + line2 + """) +} +|] diff --git a/tests/Language/GraphQL/AST/ParserSpec.hs b/tests/Language/GraphQL/AST/ParserSpec.hs index 3e20e8f..420d3cf 100644 --- a/tests/Language/GraphQL/AST/ParserSpec.hs +++ b/tests/Language/GraphQL/AST/ParserSpec.hs @@ -30,3 +30,15 @@ spec = describe "Parser" $ do mutation auth($username: String!, $password: String!){ test }|] + + it "accepts two string arguments" $ + parse document "" `shouldSucceedOn` [r| + mutation auth{ + test(username: "username", password: "password") + }|] + + it "accepts two block string arguments" $ + parse document "" `shouldSucceedOn` [r| + mutation auth{ + test(username: """username""", password: """password""") + }|] |
