From fbfbb3e73f4adc973fd2b515c4fb665e1556a214 Mon Sep 17 00:00:00 2001 From: Eugen Wissner Date: Thu, 23 Sep 2021 08:23:38 +0200 Subject: [PATCH] Remove raw-strings-qq --- graphql.cabal | 1 - tests/Language/GraphQL/AST/EncoderSpec.hs | 142 ++++++++++++++-------- tests/Language/GraphQL/AST/ParserSpec.hs | 60 ++++----- tests/Test/DirectiveSpec.hs | 12 +- tests/Test/FragmentSpec.hs | 48 ++++---- tests/Test/RootOperationSpec.hs | 6 +- 6 files changed, 156 insertions(+), 113 deletions(-) diff --git a/graphql.cabal b/graphql.cabal index 2219fed..dfa8052 100644 --- a/graphql.cabal +++ b/graphql.cabal @@ -102,7 +102,6 @@ test-suite graphql-test , hspec >= 2.8.2 && < 2.9 , hspec-megaparsec >= 2.2.0 && < 2.3 , megaparsec - , raw-strings-qq >= 1.1 && < 1.2 , scientific , text , unordered-containers diff --git a/tests/Language/GraphQL/AST/EncoderSpec.hs b/tests/Language/GraphQL/AST/EncoderSpec.hs index 0c7dd39..bc6aac4 100644 --- a/tests/Language/GraphQL/AST/EncoderSpec.hs +++ b/tests/Language/GraphQL/AST/EncoderSpec.hs @@ -6,10 +6,10 @@ module Language.GraphQL.AST.EncoderSpec import qualified Language.GraphQL.AST.Document as Full import Language.GraphQL.AST.Encoder +import Language.GraphQL.TH import Test.Hspec (Spec, context, describe, it, shouldBe, shouldStartWith, shouldEndWith, shouldNotContain) import Test.QuickCheck (choose, oneof, forAll) -import Text.RawString.QQ (r) -import Data.Text.Lazy (cons, toStrict, unpack) +import qualified Data.Text.Lazy as Text.Lazy spec :: Spec spec = do @@ -48,23 +48,32 @@ spec = do it "uses strings for short string values" $ value pretty (Full.String "Short text") `shouldBe` "\"Short text\"" it "uses block strings for text with new lines, with newline symbol" $ - value pretty (Full.String "Line 1\nLine 2") - `shouldBe` [r|""" - Line 1 - Line 2 -"""|] + let expected = [gql| + """ + Line 1 + Line 2 + """ + |] + actual = value pretty $ Full.String "Line 1\nLine 2" + in actual `shouldBe` expected it "uses block strings for text with new lines, with CR symbol" $ - value pretty (Full.String "Line 1\rLine 2") - `shouldBe` [r|""" - Line 1 - Line 2 -"""|] + let expected = [gql| + """ + Line 1 + Line 2 + """ + |] + actual = value pretty $ Full.String "Line 1\rLine 2" + in actual `shouldBe` expected it "uses block strings for text with new lines, with CR symbol followed by newline" $ - value pretty (Full.String "Line 1\r\nLine 2") - `shouldBe` [r|""" - Line 1 - Line 2 -"""|] + let expected = [gql| + """ + Line 1 + Line 2 + """ + |] + actual = value pretty $ Full.String "Line 1\r\nLine 2" + in actual `shouldBe` expected it "encodes as one line string if has escaped symbols" $ do let genNotAllowedSymbol = oneof @@ -76,48 +85,74 @@ spec = do forAll genNotAllowedSymbol $ \x -> do let - rawValue = "Short \n" <> cons x "text" - encoded = value pretty (Full.String $ toStrict rawValue) - shouldStartWith (unpack encoded) "\"" - shouldEndWith (unpack encoded) "\"" - shouldNotContain (unpack encoded) "\"\"\"" + rawValue = "Short \n" <> Text.Lazy.cons x "text" + encoded = value pretty + $ Full.String $ Text.Lazy.toStrict rawValue + shouldStartWith (Text.Lazy.unpack encoded) "\"" + shouldEndWith (Text.Lazy.unpack encoded) "\"" + shouldNotContain (Text.Lazy.unpack encoded) "\"\"\"" - it "Hello world" $ value pretty (Full.String "Hello,\n World!\n\nYours,\n GraphQL.") - `shouldBe` [r|""" - Hello, - World! + it "Hello world" $ + let actual = value pretty + $ Full.String "Hello,\n World!\n\nYours,\n GraphQL." + expected = [gql| + """ + Hello, + World! - Yours, - GraphQL. -"""|] + Yours, + GraphQL. + """ + |] + in actual `shouldBe` expected - it "has only newlines" $ value pretty (Full.String "\n") `shouldBe` [r|""" + it "has only newlines" $ + let actual = value pretty $ Full.String "\n" + expected = [gql| + """ -"""|] + """ + |] + in actual `shouldBe` expected it "has newlines and one symbol at the begining" $ - value pretty (Full.String "a\n\n") `shouldBe` [r|""" - a + let actual = value pretty $ Full.String "a\n\n" + expected = [gql| + """ + a -"""|] + """|] + in actual `shouldBe` expected it "has newlines and one symbol at the end" $ - value pretty (Full.String "\n\na") `shouldBe` [r|""" + let actual = value pretty $ Full.String "\n\na" + expected = [gql| + """ - a -"""|] + a + """ + |] + in actual `shouldBe` expected it "has newlines and one symbol in the middle" $ - value pretty (Full.String "\na\n") `shouldBe` [r|""" + let actual = value pretty $ Full.String "\na\n" + expected = [gql| + """ - a + a -"""|] - it "skip trailing whitespaces" $ value pretty (Full.String " Short\ntext ") - `shouldBe` [r|""" - Short - text -"""|] + """ + |] + in actual `shouldBe` expected + it "skip trailing whitespaces" $ + let actual = value pretty $ Full.String " Short\ntext " + expected = [gql| + """ + Short + text + """ + |] + in actual `shouldBe` expected describe "definition" $ it "indents block strings in arguments" $ @@ -128,10 +163,13 @@ spec = do fieldSelection = pure $ Full.FieldSelection field operation = Full.DefinitionOperation $ Full.SelectionSet fieldSelection location - in definition pretty operation `shouldBe` [r|{ - field(message: """ - line1 - line2 - """) -} -|] + expected = Text.Lazy.snoc [gql| + { + field(message: """ + line1 + line2 + """) + } + |] '\n' + actual = definition pretty operation + in actual `shouldBe` expected diff --git a/tests/Language/GraphQL/AST/ParserSpec.hs b/tests/Language/GraphQL/AST/ParserSpec.hs index a47fc11..702beab 100644 --- a/tests/Language/GraphQL/AST/ParserSpec.hs +++ b/tests/Language/GraphQL/AST/ParserSpec.hs @@ -8,10 +8,10 @@ import Data.List.NonEmpty (NonEmpty(..)) 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.Megaparsec (shouldParse, shouldFailOn, shouldSucceedOn) import Text.Megaparsec (parse) -import Text.RawString.QQ (r) spec :: Spec spec = describe "Parser" $ do @@ -19,74 +19,74 @@ spec = describe "Parser" $ do parse document "" `shouldSucceedOn` "\xfeff{foo}" it "accepts block strings as argument" $ - parse document "" `shouldSucceedOn` [r|{ + parse document "" `shouldSucceedOn` [gql|{ hello(text: """Argument""") }|] it "accepts strings as argument" $ - parse document "" `shouldSucceedOn` [r|{ + parse document "" `shouldSucceedOn` [gql|{ hello(text: "Argument") }|] it "accepts two required arguments" $ - parse document "" `shouldSucceedOn` [r| + parse document "" `shouldSucceedOn` [gql| mutation auth($username: String!, $password: String!){ test }|] it "accepts two string arguments" $ - parse document "" `shouldSucceedOn` [r| + parse document "" `shouldSucceedOn` [gql| mutation auth{ test(username: "username", password: "password") }|] it "accepts two block string arguments" $ - parse document "" `shouldSucceedOn` [r| + parse document "" `shouldSucceedOn` [gql| mutation auth{ test(username: """username""", password: """password""") }|] it "parses minimal schema definition" $ - parse document "" `shouldSucceedOn` [r|schema { query: Query }|] + parse document "" `shouldSucceedOn` [gql|schema { query: Query }|] it "parses minimal scalar definition" $ - parse document "" `shouldSucceedOn` [r|scalar Time|] + parse document "" `shouldSucceedOn` [gql|scalar Time|] it "parses ImplementsInterfaces" $ - parse document "" `shouldSucceedOn` [r| + parse document "" `shouldSucceedOn` [gql| type Person implements NamedEntity & ValuedEntity { name: String } |] it "parses a type without ImplementsInterfaces" $ - parse document "" `shouldSucceedOn` [r| + parse document "" `shouldSucceedOn` [gql| type Person { name: String } |] it "parses ArgumentsDefinition in an ObjectDefinition" $ - parse document "" `shouldSucceedOn` [r| + parse document "" `shouldSucceedOn` [gql| type Person { name(first: String, last: String): String } |] it "parses minimal union type definition" $ - parse document "" `shouldSucceedOn` [r| + parse document "" `shouldSucceedOn` [gql| union SearchResult = Photo | Person |] it "parses minimal interface type definition" $ - parse document "" `shouldSucceedOn` [r| + parse document "" `shouldSucceedOn` [gql| interface NamedEntity { name: String } |] it "parses minimal enum type definition" $ - parse document "" `shouldSucceedOn` [r| + parse document "" `shouldSucceedOn` [gql| enum Direction { NORTH EAST @@ -96,7 +96,7 @@ spec = describe "Parser" $ do |] it "parses minimal enum type definition" $ - parse document "" `shouldSucceedOn` [r| + parse document "" `shouldSucceedOn` [gql| enum Direction { NORTH EAST @@ -106,7 +106,7 @@ spec = describe "Parser" $ do |] it "parses minimal input object type definition" $ - parse document "" `shouldSucceedOn` [r| + parse document "" `shouldSucceedOn` [gql| input Point2D { x: Float y: Float @@ -114,7 +114,7 @@ spec = describe "Parser" $ do |] it "parses minimal input enum definition with an optional pipe" $ - parse document "" `shouldSucceedOn` [r| + parse document "" `shouldSucceedOn` [gql| directive @example on | FIELD | FRAGMENT_SPREAD @@ -131,15 +131,15 @@ spec = describe "Parser" $ do example1 = directive "example1" (DirLoc.TypeSystemDirectiveLocation DirLoc.FieldDefinition) - (Location {line = 2, column = 17}) + (Location {line = 1, column = 1}) example2 = directive "example2" (DirLoc.ExecutableDirectiveLocation DirLoc.Field) - (Location {line = 3, column = 17}) + (Location {line = 2, column = 1}) testSchemaExtension = example1 :| [ example2 ] - query = [r| - directive @example1 on FIELD_DEFINITION - directive @example2 on FIELD + query = [gql| + directive @example1 on FIELD_DEFINITION + directive @example2 on FIELD |] in parse document "" query `shouldParse` testSchemaExtension @@ -167,16 +167,16 @@ spec = describe "Parser" $ do $ Node (ConstList []) $ Location {line = 1, column = 33})] (Location {line = 1, column = 1}) - query = [r|directive @test(foo: [String] = []) on FIELD_DEFINITION|] + query = [gql|directive @test(foo: [String] = []) on FIELD_DEFINITION|] in parse document "" query `shouldParse` (defn :| [ ]) it "parses schema extension with a new directive" $ - parse document "" `shouldSucceedOn`[r| + parse document "" `shouldSucceedOn`[gql| extend schema @newDirective |] it "parses schema extension with an operation type definition" $ - parse document "" `shouldSucceedOn` [r|extend schema { query: Query }|] + parse document "" `shouldSucceedOn` [gql|extend schema { query: Query }|] it "parses schema extension with an operation type and directive" $ let newDirective = Directive "newDirective" [] $ Location 1 15 @@ -185,25 +185,25 @@ spec = describe "Parser" $ do $ OperationTypeDefinition Query "Query" :| [] testSchemaExtension = TypeSystemExtension schemaExtension $ Location 1 1 - query = [r|extend schema @newDirective { query: Query }|] + query = [gql|extend schema @newDirective { query: Query }|] in parse document "" query `shouldParse` (testSchemaExtension :| []) it "parses an object extension" $ - parse document "" `shouldSucceedOn` [r| + parse document "" `shouldSucceedOn` [gql| extend type Story { isHiddenLocally: Boolean } |] it "rejects variables in DefaultValue" $ - parse document "" `shouldFailOn` [r| + parse document "" `shouldFailOn` [gql| query ($book: String = "Zarathustra", $author: String = $book) { title } |] it "parses documents beginning with a comment" $ - parse document "" `shouldSucceedOn` [r| + parse document "" `shouldSucceedOn` [gql| """ Query """ @@ -213,7 +213,7 @@ spec = describe "Parser" $ do |] it "parses subscriptions" $ - parse document "" `shouldSucceedOn` [r| + parse document "" `shouldSucceedOn` [gql| subscription NewMessages { newMessage(roomId: 123) { sender diff --git a/tests/Test/DirectiveSpec.hs b/tests/Test/DirectiveSpec.hs index 2d586f6..50caa5b 100644 --- a/tests/Test/DirectiveSpec.hs +++ b/tests/Test/DirectiveSpec.hs @@ -12,11 +12,11 @@ import Data.Aeson (object, (.=)) import qualified Data.Aeson as Aeson import qualified Data.HashMap.Strict as HashMap import Language.GraphQL +import Language.GraphQL.TH import Language.GraphQL.Type import qualified Language.GraphQL.Type.Out as Out import Test.Hspec (Spec, describe, it) import Test.Hspec.GraphQL -import Text.RawString.QQ (r) experimentalResolver :: Schema IO experimentalResolver = schema queryType Nothing Nothing mempty @@ -33,7 +33,7 @@ spec :: Spec spec = describe "Directive executor" $ do it "should be able to @skip fields" $ do - let sourceQuery = [r| + let sourceQuery = [gql| { experimentalField @skip(if: true) } @@ -43,7 +43,7 @@ spec = actual `shouldResolveTo` emptyObject it "should not skip fields if @skip is false" $ do - let sourceQuery = [r| + let sourceQuery = [gql| { experimentalField @skip(if: false) } @@ -56,7 +56,7 @@ spec = actual `shouldResolveTo` expected it "should skip fields if @include is false" $ do - let sourceQuery = [r| + let sourceQuery = [gql| { experimentalField @include(if: false) } @@ -66,7 +66,7 @@ spec = actual `shouldResolveTo` emptyObject it "should be able to @skip a fragment spread" $ do - let sourceQuery = [r| + let sourceQuery = [gql| { ...experimentalFragment @skip(if: true) } @@ -80,7 +80,7 @@ spec = actual `shouldResolveTo` emptyObject it "should be able to @skip an inline fragment" $ do - let sourceQuery = [r| + let sourceQuery = [gql| { ... on Query @skip(if: true) { experimentalField diff --git a/tests/Test/FragmentSpec.hs b/tests/Test/FragmentSpec.hs index f426e2c..5e0ae58 100644 --- a/tests/Test/FragmentSpec.hs +++ b/tests/Test/FragmentSpec.hs @@ -15,9 +15,9 @@ import Data.Text (Text) import Language.GraphQL import Language.GraphQL.Type import qualified Language.GraphQL.Type.Out as Out +import Language.GraphQL.TH import Test.Hspec (Spec, describe, it) import Test.Hspec.GraphQL -import Text.RawString.QQ (r) size :: (Text, Value) size = ("size", String "L") @@ -34,16 +34,18 @@ garment typeName = ) inlineQuery :: Text -inlineQuery = [r|{ - garment { - ... on Hat { - circumference - } - ... on Shirt { - size +inlineQuery = [gql| + { + garment { + ... on Hat { + circumference + } + ... on Shirt { + size + } } } -}|] +|] shirtType :: Out.ObjectType IO shirtType = Out.ObjectType "Shirt" Nothing [] $ HashMap.fromList @@ -106,12 +108,14 @@ spec = do in actual `shouldResolveTo` expected it "embeds inline fragments without type" $ do - let sourceQuery = [r|{ - circumference - ... { - size + let sourceQuery = [gql| + { + circumference + ... { + size + } } - }|] + |] actual <- graphql (toSchema "circumference" circumference) sourceQuery let expected = HashMap.singleton "data" $ Aeson.object @@ -121,16 +125,18 @@ spec = do in actual `shouldResolveTo` expected it "evaluates fragments on Query" $ do - let sourceQuery = [r|{ - ... { - size + let sourceQuery = [gql| + { + ... { + size + } } - }|] + |] in graphql (toSchema "size" size) `shouldResolve` sourceQuery describe "Fragment spread executor" $ do it "evaluates fragment spreads" $ do - let sourceQuery = [r| + let sourceQuery = [gql| { ...circumferenceFragment } @@ -148,7 +154,7 @@ spec = do in actual `shouldResolveTo` expected it "evaluates nested fragments" $ do - let sourceQuery = [r| + let sourceQuery = [gql| { garment { ...circumferenceFragment @@ -174,7 +180,7 @@ spec = do in actual `shouldResolveTo` expected it "considers type condition" $ do - let sourceQuery = [r| + let sourceQuery = [gql| { garment { ...circumferenceFragment diff --git a/tests/Test/RootOperationSpec.hs b/tests/Test/RootOperationSpec.hs index 1921ec9..9271c61 100644 --- a/tests/Test/RootOperationSpec.hs +++ b/tests/Test/RootOperationSpec.hs @@ -12,7 +12,7 @@ import Data.Aeson ((.=), object) import qualified Data.HashMap.Strict as HashMap import Language.GraphQL import Test.Hspec (Spec, describe, it) -import Text.RawString.QQ (r) +import Language.GraphQL.TH import Language.GraphQL.Type import qualified Language.GraphQL.Type.Out as Out import Test.Hspec.GraphQL @@ -42,7 +42,7 @@ spec :: Spec spec = describe "Root operation type" $ do it "returns objects from the root resolvers" $ do - let querySource = [r| + let querySource = [gql| { garment { circumference @@ -59,7 +59,7 @@ spec = actual `shouldResolveTo` expected it "chooses Mutation" $ do - let querySource = [r| + let querySource = [gql| mutation { incrementCircumference }