diff --git a/src/GraphQLParser.Tests/Issues/Issue82.cs b/src/GraphQLParser.Tests/Issues/Issue82.cs index 29a33986..45fc7549 100644 --- a/src/GraphQLParser.Tests/Issues/Issue82.cs +++ b/src/GraphQLParser.Tests/Issues/Issue82.cs @@ -2,12 +2,13 @@ namespace GraphQLParser.Tests; public class Issue82 { - private readonly string _query = @"query($username: String) { - Person(uname: $username, firstName: ""Pete"") { + private readonly string _query = """ +query($username: String) { + Person(uname: $username, firstName: "Pete") { id, email } } -"; +"""; [Theory] [InlineData(IgnoreOptions.None)] diff --git a/src/GraphQLParser.Tests/ParserTests.cs b/src/GraphQLParser.Tests/ParserTests.cs index 33570fcb..aaf67498 100644 --- a/src/GraphQLParser.Tests/ParserTests.cs +++ b/src/GraphQLParser.Tests/ParserTests.cs @@ -986,66 +986,66 @@ public void Should_Parse_Empty_Types(string text, ASTNodeKind kind) [InlineData(IgnoreOptions.All)] public void Descriptions_Should_Read_Correctly(IgnoreOptions options) { - var document = @" -""Super schema"" + var document = """" +"Super schema" schema { query: String } -""A JSON scalar"" +"A JSON scalar" scalar JSON -"""""" +""" Human type -"""""" +""" type Human { - """""" + """ Name of human - """""" + """ name: String - ""Test"" + "Test" test( - ""desc"" + "desc" arg: Int ): Int } -""Test interface"" +"Test interface" interface TestInterface { - ""Object name"" + "Object name" name: String } -"""""" +""" Test union -"""""" +""" union TestUnion = Test1 | Test2 -""Example enum"" +"Example enum" enum Colors { - ""Red"" RED - ""Blue"" BLUE + "Red" RED + "Blue" BLUE } -"""""" +""" This is an example input object Line two of the description -"""""" +""" input TestInputObject { - """""" + """ The value of the input object (any JSON value is accepted) - """""" + """ Value: JSON } -""Test directive"" +"Test directive" directive @TestDirective ( - ""Example"" + "Example" Value: Int ) on QUERY -".Parse(new ParserOptions { Ignore = options }); +"""".Parse(new ParserOptions { Ignore = options }); var defs = document.Definitions; defs.Count.ShouldBe(8); @@ -1119,100 +1119,100 @@ directive @TestDirective ( [InlineData(IgnoreOptions.All)] public void Descriptions_WithComments_Should_Read_Correctly_1(IgnoreOptions options) { - var document = @" + var document = """" # comment -1 -""Super schema"" +"Super schema" # comment 0 schema { query: String } # comment 1 -""A JSON scalar"" +"A JSON scalar" # comment 2 scalar JSON # comment 3 -"""""" +""" Human type -"""""" +""" # comment 4 type Human { # comment 5 - """""" + """ Name of human - """""" + """ # comment 6 name: String # comment 7 - ""Test"" + "Test" # comment 8 test( # comment 9 - ""desc"" + "desc" # comment 10 arg: Int ): Int } # comment 11 -""Test interface"" +"Test interface" # comment 12 interface TestInterface { # comment 13 - ""Object name"" + "Object name" # comment 14 name: String } # comment 15 -"""""" +""" Test union -"""""" +""" # comment 16 union TestUnion = Test1 | Test2 # comment 17 -""Example enum"" +"Example enum" # comment 18 enum Colors { # comment 19 - ""Red"" + "Red" # comment 20 RED # comment 21 - ""Blue"" + "Blue" # comment 22 BLUE } # comment 23 -"""""" +""" This is an example input object Line two of the description -"""""" +""" # comment 24 input TestInputObject { # comment 25 - """""" + """ The value of the input object (any JSON value is accepted) - """""" + """ # comment 26 Value: JSON } # comment 27 -""Test directive"" +"Test directive" # comment 28 directive @TestDirective ( # comment 29 - ""Example"" + "Example" # comment 30 Value: Int ) on QUERY -".Parse(new ParserOptions { Ignore = options }); +"""".Parse(new ParserOptions { Ignore = options }); var defs = document.Definitions; defs.Count.ShouldBe(8); var parseComments = !options.HasFlag(IgnoreOptions.Comments); @@ -1319,84 +1319,84 @@ directive @TestDirective ( [InlineData(IgnoreOptions.All)] public void Descriptions_WithComments_Should_Read_Correctly_2(IgnoreOptions options) { - var document = @" -""Super schema"" + var document = """" +"Super schema" # comment 1 schema { query: String } -""A JSON scalar"" +"A JSON scalar" # comment 2 scalar JSON -"""""" +""" Human type -"""""" +""" # comment 4 type Human { - """""" + """ Name of human - """""" + """ # comment 6 name: String - ""Test"" + "Test" # comment 8 test( - ""desc"" + "desc" # comment 10 arg: Int ): Int } -""Test interface"" +"Test interface" # comment 12 interface TestInterface { - ""Object name"" + "Object name" # comment 14 name: String } -"""""" +""" Test union -"""""" +""" # comment 16 union TestUnion = Test1 | Test2 -""Example enum"" +"Example enum" # comment 18 enum Colors { - ""Red"" + "Red" # comment 20 RED - ""Blue"" + "Blue" # comment 22 BLUE } -"""""" +""" This is an example input object Line two of the description -"""""" +""" # comment 24 input TestInputObject { - """""" + """ The value of the input object (any JSON value is accepted) - """""" + """ # comment 26 Value: JSON } -""Test directive"" +"Test directive" # comment 28 directive @TestDirective ( - ""Example"" + "Example" # comment 30 Value: Int ) on QUERY -".Parse(new ParserOptions { Ignore = options }); +"""".Parse(new ParserOptions { Ignore = options }); var defs = document.Definitions; defs.Count.ShouldBe(8); var parseComments = !options.HasFlag(IgnoreOptions.Comments); @@ -1503,84 +1503,84 @@ directive @TestDirective ( [InlineData(IgnoreOptions.All)] public void Descriptions_WithComments_Should_Read_Correctly_3(IgnoreOptions options) { - var document = @" + var document = """" # comment 0 -""Super schema"" +"Super schema" schema { query: String } # comment 1 -""A JSON scalar"" +"A JSON scalar" scalar JSON # comment 3 -"""""" +""" Human type -"""""" +""" type Human { # comment 5 - """""" + """ Name of human - """""" + """ name: String # comment 7 - ""Test"" + "Test" test( # comment 9 - ""desc"" + "desc" arg: Int ): Int } # comment 11 -""Test interface"" +"Test interface" interface TestInterface { # comment 13 - ""Object name"" + "Object name" name: String } # comment 15 -"""""" +""" Test union -"""""" +""" union TestUnion = Test1 | Test2 # comment 17 -""Example enum"" +"Example enum" enum Colors { # comment 19 - ""Red"" + "Red" RED # comment 21 - ""Blue"" + "Blue" BLUE } # comment 23 -"""""" +""" This is an example input object Line two of the description -"""""" +""" input TestInputObject { # comment 25 - """""" + """ The value of the input object (any JSON value is accepted) - """""" + """ Value: JSON } # comment 27 -""Test directive"" +"Test directive" directive @TestDirective ( # comment 29 - ""Example"" + "Example" Value: Int ) on QUERY -".Parse(new ParserOptions { Ignore = options }); +"""".Parse(new ParserOptions { Ignore = options }); var defs = document.Definitions; defs.Count.ShouldBe(8); var parseComments = !options.HasFlag(IgnoreOptions.Comments); diff --git a/src/GraphQLParser.Tests/Visitors/CountVisitorTests.cs b/src/GraphQLParser.Tests/Visitors/CountVisitorTests.cs index 7b32742e..d36dac64 100644 --- a/src/GraphQLParser.Tests/Visitors/CountVisitorTests.cs +++ b/src/GraphQLParser.Tests/Visitors/CountVisitorTests.cs @@ -8,11 +8,12 @@ public class CountVisitorTests [InlineData("query a { name age }", 8)] [InlineData("scalar JSON @exportable", 6)] [InlineData("{a}", 5)] // Document->OperationDefinition->SelectionSet->Field->Name - [InlineData(@" -""""""Very good type"""""" + [InlineData("""" +"""Very good type""" type T { # the best field ever -field: Int }", 10)] +field: Int } +"""", 10)] [InlineData("mutation add($a: Int!, $b: [Int]) { result }", 19)] [InlineData("type T implements I & K { f: ID }", 13)] [InlineData("interface I implements K", 6)] diff --git a/src/GraphQLParser.Tests/Visitors/SDLPrinterTests.cs b/src/GraphQLParser.Tests/Visitors/SDLPrinterTests.cs index 2e197be5..c5632fcc 100644 --- a/src/GraphQLParser.Tests/Visitors/SDLPrinterTests.cs +++ b/src/GraphQLParser.Tests/Visitors/SDLPrinterTests.cs @@ -161,30 +161,32 @@ ... on CustomerType { [InlineData(18, @"extend input Foo @exportable", @"extend input Foo @exportable")] - [InlineData(19, -@"#comment + [InlineData(19, """ +#comment input Example @x #comment on fields { self: [Example!]! - value: String = ""xyz"" + value: String = "xyz" } input B -input C", -@"#comment +input C +""", """ +#comment input Example @x #comment on fields { self: [Example!]! - value: String = ""xyz"" + value: String = "xyz" } input B -input C")] - [InlineData(20, -@"query inlineFragmentTyping { - profiles(handles: [""zuck"", ""coca - cola""]) +input C +""")] + [InlineData(20, """ +query inlineFragmentTyping { + profiles(handles: ["zuck", "coca - cola"]) { handle ... on User @@ -202,9 +204,9 @@ ... on Page } } } -", -@"query inlineFragmentTyping { - profiles(handles: [""zuck"", ""coca - cola""]) { +""", """ +query inlineFragmentTyping { + profiles(handles: ["zuck", "coca - cola"]) { handle ... on User { friends { @@ -217,7 +219,8 @@ ... on Page { } } } -}")] +} +""")] [InlineData(21, @"scalar a scalar b scalar c", @"scalar a @@ -277,81 +280,86 @@ fragment Frag on Query { @"interface Dog implements Eat & Bark { volume: Int! }")] - [InlineData(27, -@"enum Color { RED, + [InlineData(27, """" +enum Color { RED, #good color -GREEN @directive(list: [1,2.7,3,null,{}, {name:""tom"" age:42}]), -"""""" +GREEN @directive(list: [1,2.7,3,null,{}, {name:"tom" age:42}]), +""" another good color -"""""" -BLUE }", -@"enum Color { +""" +BLUE } +"""", """ +enum Color { RED #good color - GREEN @directive(list: [1, 2.7, 3, null, {}, {name: ""tom"", age: 42}]) - ""another good color"" + GREEN @directive(list: [1, 2.7, 3, null, {}, {name: "tom", age: 42}]) + "another good color" BLUE -}")] - [InlineData(28, -@"# super query +} +""")] + [InlineData(28, """ +# super query # # multiline -query summary($id: ID!, $detailed: Boolean! = true) { name(full:true,kind: UPPER) age1:age address { street @short(length:5,x:""a"", pi: 3.14) +query summary($id: ID!, $detailed: Boolean! = true) { name(full:true,kind: UPPER) age1:age address { street @short(length:5,x:"a", pi: 3.14) #need -building } }", -@"# super query +building } } +""", """ +# super query # # multiline query summary($id: ID!, $detailed: Boolean! = true) { name(full: true, kind: UPPER) age1: age address { - street @short(length: 5, x: ""a"", pi: 3.14) + street @short(length: 5, x: "a", pi: 3.14) #need building } -}")] - [InlineData(29, -@" -"""""" +} +""")] + [InlineData(29, """" +""" description indent 2 indent4 -"""""" +""" scalar JSON @exportable # A dog type Dog implements &Animal #comment on fields { - """"""inline docs"""""" + """inline docs""" volume: Float - """""" + """ multiline docs - """""" + """ friends: [Dog!] age(precise: Boolean!): Int! -}", -@""""""" +} +"""", """" +""" description indent 2 indent4 -"""""" +""" scalar JSON @exportable # A dog type Dog implements Animal #comment on fields { - ""inline docs"" + "inline docs" volume: Float - """""" + """ multiline docs - """""" + """ friends: [Dog!] age(precise: Boolean!): Int! -}")] +} +"""")] [InlineData(30, @"query q { @@ -514,32 +522,34 @@ extend enum Color #comment rendered: Boolean): String }", true)] - [InlineData(40, -@"""This is a Foo object type"" + [InlineData(40, """ +"This is a Foo object type" type Foo { - ""This is of type Integer"" + "This is of type Integer" int: Int - ""This is of type String"" + "This is of type String" str: String } type Query { foo: Foo -}", -@"""This is a Foo object type"" +} +""", """ +"This is a Foo object type" type Foo { - ""This is of type Integer"" + "This is of type Integer" int: Int - ""This is of type String"" + "This is of type String" str: String } type Query { foo: Foo -}", true)] +} +""", true)] [InlineData(41, -@"directive @skip(""Skipped when true."" if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT", +"""directive @skip("Skipped when true." if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT""", @"directive @skip( ""Skipped when true."" if: Boolean!) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT")] @@ -549,12 +559,13 @@ type Query { ""Skipped when true."" if: Boolean!, x: Some) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT")] [InlineData(43, -@"directive @skip(""Skipped when true."" if: Boolean!, ""Second argument"" x: Some) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT", -@"directive @skip( - ""Skipped when true."" +"""directive @skip("Skipped when true." if: Boolean!, "Second argument" x: Some) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT""", """ +directive @skip( + "Skipped when true." if: Boolean!, - ""Second argument"" - x: Some) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT")] + "Second argument" + x: Some) on FIELD | FRAGMENT_SPREAD | INLINE_FRAGMENT +""")] public async Task SDLPrinter_Should_Print_Document( int number, string text, @@ -738,13 +749,14 @@ public async Task Description_Without_Parent_Should_Be_Printed(string text, stri @"""a \u0010\u0011\u0012\u0013\u0014\u0015\u0016\u0017\u0018\u0019\u001A\u001B\u001C\u001D\u001E\u001F b"" ")] [InlineData( // TODO: Change test condition? -"Test\r\nLine 2\rLine 3\nLine 4", -@""""""" +"Test\r\nLine 2\rLine 3\nLine 4", """" +""" Test Line 2Line 3 Line 4 -"""""" -")] +""" + +"""")] public async Task Description_With_Escaped_Unicode_Should_Be_Printed(string text, string expected) { var description = new GraphQLDescription(text); diff --git a/src/GraphQLParser.Tests/Visitors/StructurePrinterTests.cs b/src/GraphQLParser.Tests/Visitors/StructurePrinterTests.cs index 1d90f8c8..f23b88b3 100644 --- a/src/GraphQLParser.Tests/Visitors/StructurePrinterTests.cs +++ b/src/GraphQLParser.Tests/Visitors/StructurePrinterTests.cs @@ -93,11 +93,12 @@ Name [i] Field Name [k] ")] - [InlineData(@" -""""""Very good type"""""" + [InlineData("""" +"""Very good type""" type T { # the best field ever -field: Int }", @"Document +field: Int } +"""", @"Document ObjectTypeDefinition Description Name [T]