|
1 | 1 | package graphql.parser |
2 | 2 |
|
3 | 3 | import graphql.language.* |
| 4 | +import org.antlr.v4.runtime.misc.ParseCancellationException |
4 | 5 | import spock.lang.Specification |
5 | 6 | import spock.lang.Unroll |
6 | 7 |
|
@@ -64,7 +65,7 @@ class ParserTest extends Specification { |
64 | 65 | when: |
65 | 66 | Document document = new Parser().parseDocument(input) |
66 | 67 | then: |
67 | | - isEqual(document,expectedResult) |
| 68 | + isEqual(document, expectedResult) |
68 | 69 |
|
69 | 70 | } |
70 | 71 |
|
@@ -142,7 +143,7 @@ class ParserTest extends Specification { |
142 | 143 |
|
143 | 144 | then: |
144 | 145 | document.definitions.size() == 2 |
145 | | - isEqual(document.definitions[0],queryDefinition) |
| 146 | + isEqual(document.definitions[0], queryDefinition) |
146 | 147 | isEqual(document.definitions[1], fragmentDefinition) |
147 | 148 | } |
148 | 149 |
|
@@ -310,7 +311,7 @@ class ParserTest extends Specification { |
310 | 311 | Field helloField = document.definitions[0].selectionSet.selections[0] |
311 | 312 |
|
312 | 313 | then: |
313 | | - isEqual(helloField,new Field("hello", [new Argument("arg", new StringValue("hello, world"))])) |
| 314 | + isEqual(helloField, new Field("hello", [new Argument("arg", new StringValue("hello, world"))])) |
314 | 315 | } |
315 | 316 |
|
316 | 317 | @Unroll |
@@ -338,4 +339,26 @@ class ParserTest extends Specification { |
338 | 339 |
|
339 | 340 | } |
340 | 341 |
|
| 342 | + def "extraneous input is an excpetion"() { |
| 343 | + given: |
| 344 | + def input = """ |
| 345 | + mutation event(\$var: SomeType[]!) { res: update(arg: \$var) {id} } |
| 346 | + """ |
| 347 | + when: |
| 348 | + new Parser().parseDocument(input) |
| 349 | + then: |
| 350 | + thrown(ParseCancellationException) |
| 351 | + } |
| 352 | + |
| 353 | + def "invalid syntax is an error"() { |
| 354 | + given: |
| 355 | + def input = """ |
| 356 | + mutation event(() } |
| 357 | + """ |
| 358 | + when: |
| 359 | + new Parser().parseDocument(input) |
| 360 | + then: |
| 361 | + thrown(ParseCancellationException) |
| 362 | + } |
| 363 | + |
341 | 364 | } |
0 commit comments