lexer_test.yml

  1encoding:
  2  - name: disallows uncommon control characters
  3    input: "\u0007"
  4    error:
  5      message: 'Cannot contain the invalid character "\u0007"'
  6      locations: [{line: 1, column: 1}]
  7
  8  - name: accepts BOM header
  9    input: "\uFEFF foo"
 10    tokens:
 11      -
 12        kind: NAME
 13        start: 2
 14        end: 5
 15        value: 'foo'
 16
 17simple tokens:
 18  - name: records line and column
 19    input: "\n \r\n \r  foo\n"
 20    tokens:
 21      -
 22        kind: NAME
 23        start: 8
 24        end: 11
 25        line: 4
 26        column: 3
 27        value: 'foo'
 28
 29  - name: skips whitespace
 30    input: "\n\n    foo\n\n\n"
 31    tokens:
 32      -
 33        kind: NAME
 34        start: 6
 35        end: 9
 36        value: 'foo'
 37
 38  - name: skips comments
 39    input: "\n    #comment\n    foo#comment\n"
 40    tokens:
 41      -
 42        kind: NAME
 43        start: 18
 44        end: 21
 45        value: 'foo'
 46
 47  - name: skips commas
 48    input: ",,,foo,,,"
 49    tokens:
 50      -
 51        kind: NAME
 52        start: 3
 53        end: 6
 54        value: 'foo'
 55
 56  - name: errors respect whitespace
 57    input: "\n\n    ?\n\n\n"
 58    error:
 59      message: 'Cannot parse the unexpected character "?".'
 60      locations: [{line: 3, column: 5}]
 61      string: |
 62        Syntax Error: Cannot parse the unexpected character "?".
 63        GraphQL request (3:5)
 64        2:
 65        3:     ?
 66               ^
 67        4:
 68
 69  - name: lex reports useful information for dashes in names
 70    input: "a-b"
 71    error:
 72      message: 'Invalid number, expected digit but got: "b".'
 73      locations: [{ line: 1, column: 3 }]
 74    tokens:
 75      -
 76        kind: Name
 77        start: 0
 78        end: 1
 79        value: a
 80
 81lexes strings:
 82  - name: basic
 83    input: '"simple"'
 84    tokens:
 85      -
 86        kind: STRING
 87        start: 0
 88        end: 8
 89        value: 'simple'
 90
 91  - name: whitespace
 92    input: '" white space "'
 93    tokens:
 94      -
 95        kind: STRING
 96        start: 0
 97        end: 15
 98        value: ' white space '
 99
100  - name: quote
101    input: '"quote \""'
102    tokens:
103      -
104        kind: STRING
105        start: 0
106        end: 10
107        value: 'quote "'
108
109  - name: escaped
110    input: '"escaped \n\r\b\t\f"'
111    tokens:
112      -
113        kind: STRING
114        start: 0
115        end: 20
116        value: "escaped \n\r\b\t\f"
117
118  - name: slashes
119    input: '"slashes \\ \/"'
120    tokens:
121      -
122        kind: STRING
123        start: 0
124        end: 15
125        value: 'slashes \ /'
126
127  - name: unicode
128    input: '"unicode \u1234\u5678\u90AB\uCDEF"'
129    tokens:
130      -
131        kind: STRING
132        start: 0
133        end: 34
134        value: "unicode \u1234\u5678\u90AB\uCDEF"
135
136lex reports useful string errors:
137  - name: unterminated
138    input: '"'
139    error:
140      message: "Unterminated string."
141      locations: [{ line: 1, column: 2 }]
142
143  - name: no end quote
144    input: '"no end quote'
145    error:
146      message: 'Unterminated string.'
147      locations: [{ line: 1, column: 14 }]
148
149  - name: single quotes
150    input: "'single quotes'"
151    error:
152      message: "Unexpected single quote character ('), did you mean to use a double quote (\")?"
153      locations: [{ line: 1, column: 1 }]
154
155  - name: control characters
156    input: "\"contains unescaped \u0007 control char\""
157    error:
158      message: 'Invalid character within String: "\u0007".'
159      locations: [{ line: 1, column: 21 }]
160
161  - name: null byte
162    input: "\"null-byte is not \u0000 end of file\""
163    error:
164      message: 'Invalid character within String: "\u0000".'
165      locations: [{ line: 1, column: 19 }]
166
167  - name: unterminated newline
168    input: "\"multi\nline\""
169    error:
170      message: 'Unterminated string.'
171      locations: [{line: 1, column: 7 }]
172
173  - name: unterminated carriage return
174    input: "\"multi\rline\""
175    error:
176      message: 'Unterminated string.'
177      locations: [{ line: 1, column: 7 }]
178
179  - name: bad escape character
180    input: '"bad \z esc"'
181    error:
182      message: 'Invalid character escape sequence: \z.'
183      locations: [{ line: 1, column: 7 }]
184
185  - name: hex escape sequence
186    input: '"bad \x esc"'
187    error:
188      message: 'Invalid character escape sequence: \x.'
189      locations: [{ line: 1, column: 7 }]
190
191  - name: short escape sequence
192    input: '"bad \u1 esc"'
193    error:
194      message: 'Invalid character escape sequence: \u1 es.'
195      locations: [{ line: 1, column: 7 }]
196
197  - name: invalid escape sequence 1
198    input: '"bad \u0XX1 esc"'
199    error:
200      message: 'Invalid character escape sequence: \u0XX1.'
201      locations: [{ line: 1, column: 7 }]
202
203  - name: invalid escape sequence 2
204    input: '"bad \uXXXX esc"'
205    error:
206      message: 'Invalid character escape sequence: \uXXXX.'
207      locations: [{ line: 1, column: 7 }]
208
209  - name: invalid escape sequence 3
210    input: '"bad \uFXXX esc"'
211    error:
212      message: 'Invalid character escape sequence: \uFXXX.'
213      locations: [{ line: 1, column: 7 }]
214
215  - name: invalid character escape sequence
216    input: '"bad \uXXXF esc"'
217    error:
218      message: 'Invalid character escape sequence: \uXXXF.'
219      locations: [{ line: 1, column: 7 }]
220
221lexes block strings:
222  - name: simple
223    input: '"""simple"""'
224    tokens:
225      -
226        kind: BLOCK_STRING
227        start: 0
228        end: 12
229        value: 'simple'
230
231  - name: white space
232    input: '""" white space """'
233    tokens:
234      -
235        kind: BLOCK_STRING
236        start: 0
237        end: 19
238        value: ' white space '
239
240  - name: contains quote
241    input: '"""contains " quote"""'
242    tokens:
243      -
244        kind: BLOCK_STRING
245        start: 0
246        end: 22
247        value: 'contains " quote'
248
249  - name: contains triplequote
250    input: "\"\"\"contains \\\"\"\" triplequote\"\"\""
251    tokens:
252      -
253        kind: BLOCK_STRING
254        start: 0
255        end: 31
256        value: 'contains """ triplequote'
257
258  - name: multi line
259    input: "\"\"\"multi\nline\"\"\""
260    tokens:
261      -
262        kind: BLOCK_STRING
263        start: 0
264        end: 16
265        value: "multi\nline"
266
267  - name: multi line normalized
268    input: "\"\"\"multi\rline\r\nnormalized\"\"\""
269    tokens:
270      -
271        kind: BLOCK_STRING
272        start: 0
273        end: 28
274        value: "multi\nline\nnormalized"
275
276  - name: unescaped
277    input: '"""unescaped \n\r\b\t\f\u1234"""'
278    tokens:
279      -
280        kind: BLOCK_STRING
281        start: 0
282        end: 32
283        value: 'unescaped \n\r\b\t\f\u1234'
284
285  - name: slashes
286    input: '"""slashes \\ \/"""'
287    tokens:
288      -
289        kind: BLOCK_STRING
290        start: 0
291        end: 19
292        value: 'slashes \\ \/'
293
294  - name: multiple lines
295    input: |
296      """
297
298      spans
299        multiple
300          lines
301
302      """
303    tokens:
304      -
305        kind: BLOCK_STRING
306        start: 0
307        end: 36
308        value: "spans\n  multiple\n    lines"
309
310lex reports useful block string errors:
311  - name: unterminated string
312    input: '"""'
313    error:
314      message: "Unterminated string."
315      locations: [{ line: 1, column: 4 }]
316
317  - name: unescaped control characters
318    input: "\"\"\"contains unescaped \u0007 control char\"\"\""
319    error:
320      message: 'Invalid character within String: "\u0007".'
321      locations: [{ line: 1, column: 23 }]
322
323  - name: null byte
324    input: "\"\"\"null-byte is not \u0000 end of file\"\"\""
325    error:
326      message: 'Invalid character within String: "\u0000".'
327      locations: [{ line: 1, column: 21 }]
328
329lexes numbers:
330  - name: integer
331    input: "4"
332    tokens:
333      -
334        kind: INT
335        start: 0
336        end: 1
337        value: '4'
338
339  - name: float
340    input: "4.123"
341    tokens:
342      -
343        kind: FLOAT
344        start: 0
345        end: 5
346        value: '4.123'
347
348  - name: negative
349    input: "-4"
350    tokens:
351      -
352        kind: INT
353        start: 0
354        end: 2
355        value: '-4'
356
357  - name: nine
358    input: "9"
359    tokens:
360      -
361        kind: INT
362        start: 0
363        end: 1
364        value: '9'
365
366  - name: zero
367    input: "0"
368    tokens:
369      -
370        kind: INT
371        start: 0
372        end: 1
373        value: '0'
374
375  - name: negative float
376    input: "-4.123"
377    tokens:
378      -
379        kind: FLOAT
380        start: 0
381        end: 6
382        value: '-4.123'
383
384  - name: float leading zero
385    input: "0.123"
386    tokens:
387      -
388        kind: FLOAT
389        start: 0
390        end: 5
391        value: '0.123'
392
393  - name: exponent whole
394    input: "123e4"
395    tokens:
396      -
397        kind: FLOAT
398        start: 0
399        end: 5
400        value: '123e4'
401
402  - name: exponent uppercase
403    input: "123E4"
404    tokens:
405      -
406        kind: FLOAT
407        start: 0
408        end: 5
409        value: '123E4'
410
411  - name: exponent negative power
412    input: "123e-4"
413    tokens:
414      -
415        kind: FLOAT
416        start: 0
417        end: 6
418        value: '123e-4'
419
420  - name: exponent positive power
421    input: "123e+4"
422    tokens:
423      -
424        kind: FLOAT
425        start: 0
426        end: 6
427        value: '123e+4'
428
429  - name: exponent negative base
430    input: "-1.123e4"
431    tokens:
432      -
433        kind: FLOAT
434        start: 0
435        end: 8
436        value: '-1.123e4'
437
438  - name: exponent negative base upper
439    input: "-1.123E4"
440    tokens:
441      -
442        kind: FLOAT
443        start: 0
444        end: 8
445        value: '-1.123E4'
446
447  - name: exponent negative base negative power
448    input: "-1.123e-4"
449    tokens:
450      -
451        kind: FLOAT
452        start: 0
453        end: 9
454        value: '-1.123e-4'
455
456  - name: exponent negative base positive power
457    input: "-1.123e+4"
458    tokens:
459      -
460        kind: FLOAT
461        start: 0
462        end: 9
463        value: '-1.123e+4'
464
465  - name: exponent negative base large power
466    input: "-1.123e4567"
467    tokens:
468      -
469        kind: FLOAT
470        start: 0
471        end: 11
472        value: '-1.123e4567'
473
474lex reports useful number errors:
475  - name: zero
476    input: "00"
477    error:
478      message: 'Invalid number, unexpected digit after 0: "0".'
479      locations: [{ line: 1, column: 2 }]
480
481  - name: positive
482    input: "+1"
483    error:
484      message: 'Cannot parse the unexpected character "+".'
485      locations: [{ line: 1, column: 1 }]
486
487  - name: trailing dot
488    input: "1."
489    error:
490      message: 'Invalid number, expected digit but got: <EOF>.'
491      locations: [{ line: 1, column: 3 }]
492
493  - name: traililng dot exponent
494    input: "1.e1"
495    error:
496      message: 'Invalid number, expected digit but got: "e".'
497      locations: [{ line: 1, column: 3 }]
498
499  - name: missing leading zero
500    input: ".123"
501    error:
502      message: 'Cannot parse the unexpected character ".".'
503      locations: [{ line: 1, column: 1 }]
504
505  - name: characters
506    input: "1.A"
507    error:
508      message: 'Invalid number, expected digit but got: "A".'
509      locations: [{ line: 1, column: 3 }]
510
511  - name: negative characters
512    input: "-A"
513    error:
514      message: 'Invalid number, expected digit but got: "A".'
515      locations: [{ line: 1, column: 2 }]
516
517  - name: missing exponent
518    input: '1.0e'
519    error:
520      message: 'Invalid number, expected digit but got: <EOF>.'
521      locations: [{ line: 1, column: 5 }]
522
523  - name: character exponent
524    input: "1.0eA"
525    error:
526      message: 'Invalid number, expected digit but got: "A".'
527      locations: [{ line: 1, column: 5 }]
528
529lexes punctuation:
530  - name: bang
531    input: "!"
532    tokens:
533      -
534        kind: BANG
535        start: 0
536        end: 1
537        value: undefined
538
539  - name: dollar
540    input: "$"
541    tokens:
542      -
543        kind: DOLLAR
544        start: 0
545        end: 1
546        value: undefined
547
548  - name: open paren
549    input: "("
550    tokens:
551      -
552        kind: PAREN_L
553        start: 0
554        end: 1
555        value: undefined
556
557  - name: close paren
558    input: ")"
559    tokens:
560      -
561        kind: PAREN_R
562        start: 0
563        end: 1
564        value: undefined
565
566  - name: spread
567    input: "..."
568    tokens:
569      -
570        kind: SPREAD
571        start: 0
572        end: 3
573        value: undefined
574
575  - name: colon
576    input: ":"
577    tokens:
578      -
579        kind: COLON
580        start: 0
581        end: 1
582        value: undefined
583
584  - name: equals
585    input: "="
586    tokens:
587      -
588        kind: EQUALS
589        start: 0
590        end: 1
591        value: undefined
592
593  - name: at
594    input: "@"
595    tokens:
596      -
597        kind: AT
598        start: 0
599        end: 1
600        value: undefined
601
602  - name: open bracket
603    input: "["
604    tokens:
605      -
606        kind: BRACKET_L
607        start: 0
608        end: 1
609        value: undefined
610
611  - name: close bracket
612    input: "]"
613    tokens:
614      -
615        kind: BRACKET_R
616        start: 0
617        end: 1
618        value: undefined
619
620  - name: open brace
621    input: "{"
622    tokens:
623      -
624        kind: BRACE_L
625        start: 0
626        end: 1
627        value: undefined
628
629  - name: close brace
630    input: "}"
631    tokens:
632      -
633        kind: BRACE_R
634        start: 0
635        end: 1
636        value: undefined
637
638  - name: pipe
639    input: "|"
640    tokens:
641      -
642        kind: PIPE
643        start: 0
644        end: 1
645        value: undefined
646
647lex reports useful unknown character error:
648  - name: not a spread
649    input: ".."
650    error:
651      message: 'Cannot parse the unexpected character ".".'
652      locations: [{ line: 1, column: 1 }]
653
654  - name: question mark
655    input: "?"
656    error:
657      message: 'Cannot parse the unexpected character "?".'
658      message: 'Cannot parse the unexpected character "?".'
659      locations: [{ line: 1, column: 1 }]
660
661  - name: unicode 203
662    input: "\u203B"
663    error:
664      message: 'Cannot parse the unexpected character "â".'
665      locations: [{ line: 1, column: 1 }]
666
667  - name: unicode 200
668    input: "\u200b"
669    error:
670      message: 'Cannot parse the unexpected character "â".'
671      locations: [{ line: 1, column: 1 }]
672