...

Text file src/github.com/vektah/gqlparser/v2/lexer/lexer_test.yml

Documentation: github.com/vektah/gqlparser/v2/lexer

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

View as plain text