@@ -93,3 +93,42 @@ func TestConsume(t *testing.T) {
93
93
})
94
94
}
95
95
}
96
+
97
+ var multilineStringTests = []consumeTestCase {
98
+ {
99
+ description : "Oneline strings are okay" ,
100
+ definition : `"Hello World"` ,
101
+ expected : "" ,
102
+ failureExpected : false ,
103
+ useStringDescriptions : true ,
104
+ },
105
+ {
106
+ description : "Multiline strings are not allowed" ,
107
+ definition : `"Hello
108
+ World"` ,
109
+ expected : `graphql: syntax error: literal not terminated (line 1, column 1)` ,
110
+ failureExpected : true ,
111
+ useStringDescriptions : true ,
112
+ },
113
+ }
114
+
115
+ func TestMultilineString (t * testing.T ) {
116
+ for _ , test := range multilineStringTests {
117
+ t .Run (test .description , func (t * testing.T ) {
118
+ lex := common .NewLexer (test .definition , test .useStringDescriptions )
119
+
120
+ err := lex .CatchSyntaxError (func () { lex .ConsumeWhitespace () })
121
+ if test .failureExpected && err == nil {
122
+ t .Fatalf ("Test '%s' should fail" , test .description )
123
+ } else if test .failureExpected && err != nil {
124
+ if test .expected != err .Error () {
125
+ t .Fatalf ("Test '%s' failed with wrong error: '%s'. Error should be: '%s'" , test .description , err .Error (), test .expected )
126
+ }
127
+ }
128
+
129
+ if ! test .failureExpected && err != nil {
130
+ t .Fatalf ("Test '%s' failed with error: '%s'" , test .description , err .Error ())
131
+ }
132
+ })
133
+ }
134
+ }
0 commit comments