graphql.test.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. /*---------------------------------------------------------------------------------------------
  2. * Copyright (c) Microsoft Corporation. All rights reserved.
  3. * Licensed under the MIT License. See License.txt in the project root for license information.
  4. *--------------------------------------------------------------------------------------------*/
  5. import { testTokenization } from '../test/testRunner';
  6. testTokenization('graphql', [
  7. // Keywords
  8. [
  9. {
  10. line: 'scalar Date',
  11. tokens: [
  12. { startIndex: 0, type: 'keyword.gql' },
  13. { startIndex: 6, type: '' },
  14. { startIndex: 7, type: 'type.identifier.gql' }
  15. ]
  16. }
  17. ],
  18. // Root schema definition
  19. [
  20. {
  21. line: 'schema { query: Query, mutation: Mutation subscription: Subscription }',
  22. tokens: [
  23. { startIndex: 0, type: 'keyword.gql' },
  24. { startIndex: 6, type: '' },
  25. { startIndex: 7, type: 'delimiter.curly.gql' },
  26. { startIndex: 8, type: '' },
  27. { startIndex: 9, type: 'keyword.gql' }, // this should be identifier
  28. { startIndex: 14, type: 'operator.gql' },
  29. { startIndex: 15, type: '' },
  30. { startIndex: 16, type: 'type.identifier.gql' },
  31. { startIndex: 21, type: 'delimiter.gql' },
  32. { startIndex: 22, type: '' },
  33. { startIndex: 23, type: 'keyword.gql' }, // this should be identifier
  34. { startIndex: 31, type: 'operator.gql' },
  35. { startIndex: 32, type: '' },
  36. { startIndex: 33, type: 'type.identifier.gql' },
  37. { startIndex: 41, type: '' },
  38. { startIndex: 42, type: 'keyword.gql' }, // this should be identifier
  39. { startIndex: 54, type: 'operator.gql' },
  40. { startIndex: 55, type: '' },
  41. { startIndex: 56, type: 'type.identifier.gql' },
  42. { startIndex: 68, type: '' },
  43. { startIndex: 69, type: 'delimiter.curly.gql' }
  44. ]
  45. }
  46. ],
  47. [
  48. {
  49. line: `query testQuery($intValue:Int=3){value(arg:{string:"string" int:$intValue}){field1 field2}}`,
  50. tokens: [
  51. { startIndex: 0, type: 'keyword.gql' }, // 'query'
  52. { startIndex: 5, type: '' }, // ' '
  53. { startIndex: 6, type: 'key.identifier.gql' }, // 'testQuery'
  54. { startIndex: 15, type: 'delimiter.parenthesis.gql' }, // '('
  55. { startIndex: 16, type: 'argument.identifier.gql' }, // '$intValue'
  56. { startIndex: 25, type: 'operator.gql' }, // ':'
  57. { startIndex: 26, type: 'keyword.gql' }, // 'Int'
  58. { startIndex: 29, type: 'operator.gql' }, // '='
  59. { startIndex: 30, type: 'number.gql' }, // '3'
  60. { startIndex: 31, type: 'delimiter.parenthesis.gql' }, // ')'
  61. { startIndex: 32, type: 'delimiter.curly.gql' }, // '{'
  62. { startIndex: 33, type: 'key.identifier.gql' }, // 'value'
  63. { startIndex: 38, type: 'delimiter.parenthesis.gql' }, // '('
  64. { startIndex: 39, type: 'key.identifier.gql' }, // 'arg'
  65. { startIndex: 42, type: 'operator.gql' }, // ':'
  66. { startIndex: 43, type: 'delimiter.curly.gql' }, // '{'
  67. { startIndex: 44, type: 'key.identifier.gql' }, // 'string'
  68. { startIndex: 50, type: 'operator.gql' }, // ':'
  69. { startIndex: 51, type: 'string.quote.gql' }, // '"'
  70. { startIndex: 52, type: 'string.gql' }, // 'string'
  71. { startIndex: 58, type: 'string.quote.gql' }, // '"'
  72. { startIndex: 59, type: '' }, // ' '
  73. { startIndex: 60, type: 'key.identifier.gql' }, // 'int'
  74. { startIndex: 63, type: 'operator.gql' }, // ':'
  75. { startIndex: 64, type: 'argument.identifier.gql' }, // '$intValue'
  76. { startIndex: 73, type: 'delimiter.curly.gql' }, // '}'
  77. { startIndex: 74, type: 'delimiter.parenthesis.gql' }, // ')'
  78. { startIndex: 75, type: 'delimiter.curly.gql' }, // '{'
  79. { startIndex: 76, type: 'key.identifier.gql' }, // 'field1'
  80. { startIndex: 82, type: '' }, // ' '
  81. { startIndex: 83, type: 'key.identifier.gql' }, // 'field2'
  82. { startIndex: 89, type: 'delimiter.curly.gql' } // '}}'
  83. ]
  84. }
  85. ],
  86. // More complex test:
  87. // """
  88. // Node interface
  89. // - allows (re)fetch arbitrary entity only by ID
  90. // """
  91. // interface Node {
  92. // id: ID!
  93. // }
  94. [
  95. {
  96. line: '"""',
  97. tokens: [{ startIndex: 0, type: 'string.gql' }]
  98. },
  99. {
  100. line: 'This is MarkDown',
  101. tokens: [{ startIndex: 0, type: '' }]
  102. },
  103. {
  104. line: '"""',
  105. tokens: [{ startIndex: 0, type: 'string.gql' }]
  106. },
  107. {
  108. line: 'interface Node {',
  109. tokens: [
  110. { startIndex: 0, type: 'keyword.gql' },
  111. { startIndex: 9, type: '' },
  112. { startIndex: 10, type: 'type.identifier.gql' },
  113. { startIndex: 14, type: '' },
  114. { startIndex: 15, type: 'delimiter.curly.gql' }
  115. ]
  116. },
  117. {
  118. line: ' id: ID!',
  119. tokens: [
  120. { startIndex: 0, type: '' },
  121. { startIndex: 2, type: 'key.identifier.gql' },
  122. { startIndex: 4, type: 'operator.gql' },
  123. { startIndex: 5, type: '' },
  124. { startIndex: 6, type: 'keyword.gql' },
  125. { startIndex: 8, type: 'operator.gql' }
  126. ]
  127. },
  128. {
  129. line: '}',
  130. tokens: [{ startIndex: 0, type: 'delimiter.curly.gql' }]
  131. }
  132. ]
  133. ]);