Remove raw-strings-qq

This commit is contained in:
Eugen Wissner 2021-09-23 08:23:38 +02:00
parent eedab9e742
commit fbfbb3e73f
Signed by: belka
GPG Key ID: A27FDC1E8EE902C0
6 changed files with 156 additions and 113 deletions

View File

@ -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

View File

@ -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|"""
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|"""
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|"""
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|"""
it "Hello world" $
let actual = value pretty
$ Full.String "Hello,\n World!\n\nYours,\n GraphQL."
expected = [gql|
"""
Hello,
World!
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|"""
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
"""|]
"""
|]
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
"""|]
it "skip trailing whitespaces" $ value pretty (Full.String " Short\ntext ")
`shouldBe` [r|"""
"""
|]
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|{
expected = Text.Lazy.snoc [gql|
{
field(message: """
line1
line2
""")
}
|]
}
|] '\n'
actual = definition pretty operation
in actual `shouldBe` expected

View File

@ -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,13 +131,13 @@ 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|
query = [gql|
directive @example1 on FIELD_DEFINITION
directive @example2 on FIELD
|]
@ -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

View File

@ -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

View File

@ -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,7 +34,8 @@ garment typeName =
)
inlineQuery :: Text
inlineQuery = [r|{
inlineQuery = [gql|
{
garment {
... on Hat {
circumference
@ -43,7 +44,8 @@ inlineQuery = [r|{
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|{
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|{
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

View File

@ -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
}