diff options
| author | Eugen Wissner <belka@caraus.de> | 2019-12-21 09:16:41 +0100 |
|---|---|---|
| committer | Eugen Wissner <belka@caraus.de> | 2019-12-21 09:25:05 +0100 |
| commit | b215e1a4a77368542c1b46fec234378feda4adce (patch) | |
| tree | 0e7f60eb3cc51e00c4c34382abd335a6a0e8de91 /tests/Language/GraphQL/AST | |
| parent | 1e55f17e7e85e67d6c30c1d60d2e9ade3d89ed15 (diff) | |
| download | graphql-b215e1a4a77368542c1b46fec234378feda4adce.tar.gz | |
Pretify multi-line string arguments as block strings
Fixes #10.
Diffstat (limited to 'tests/Language/GraphQL/AST')
| -rw-r--r-- | tests/Language/GraphQL/AST/EncoderSpec.hs | 53 |
1 files changed, 38 insertions, 15 deletions
diff --git a/tests/Language/GraphQL/AST/EncoderSpec.hs b/tests/Language/GraphQL/AST/EncoderSpec.hs index 47718d2..0067c83 100644 --- a/tests/Language/GraphQL/AST/EncoderSpec.hs +++ b/tests/Language/GraphQL/AST/EncoderSpec.hs @@ -1,23 +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` "\"\\\"\"" - it "escapes backspace" $ - value minified (String "a\bc") `shouldBe` "\"a\\bc\"" - it "escapes Unicode" $ - value minified (String "\0") `shouldBe` "\"\\u0000\"" +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 + """) +} +|] |
