@@ -93,3 +93,43 @@ 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
+
122
+ if test .failureExpected && err == nil {
123
+ t .Fatalf ("Test '%s' should fail" , test .description )
124
+ } else if test .failureExpected && err != nil {
125
+ if test .expected != err .Error () {
126
+ t .Fatalf ("Test '%s' failed with wrong error: '%s'. Error should be: '%s'" , test .description , err .Error (), test .expected )
127
+ }
128
+ }
129
+
130
+ if ! test .failureExpected && err != nil {
131
+ t .Fatalf ("Test '%s' failed with error: '%s'" , test .description , err .Error ())
132
+ }
133
+ })
134
+ }
135
+ }
0 commit comments