graphql.test.ts 5.0 KB

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