sparql.test.ts 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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('sparql', [
  7. // Comments
  8. [
  9. {
  10. line: '# a comment',
  11. tokens: [{ startIndex: 0, type: 'comment.rq' }]
  12. }
  13. ],
  14. [
  15. {
  16. line: '##sticky # comment',
  17. tokens: [{ startIndex: 0, type: 'comment.rq' }]
  18. }
  19. ],
  20. [
  21. {
  22. line: '"lex"^^<https://test/ns#not-a-comment>',
  23. tokens: [
  24. { startIndex: 0, type: 'string.sql.rq' },
  25. { startIndex: 5, type: 'operator.sql.rq' },
  26. { startIndex: 7, type: 'tag.rq' }
  27. ]
  28. }
  29. ],
  30. // strings
  31. [
  32. {
  33. line: '(?x ns:p "abc")',
  34. tokens: [
  35. { startIndex: 0, type: 'delimiter.parenthesis.rq' },
  36. { startIndex: 1, type: 'identifier.rq' },
  37. { startIndex: 3, type: 'white.rq' },
  38. { startIndex: 4, type: 'tag.rq' },
  39. { startIndex: 8, type: 'white.rq' },
  40. { startIndex: 9, type: 'string.sql.rq' },
  41. { startIndex: 14, type: 'delimiter.parenthesis.rq' }
  42. ]
  43. }
  44. ],
  45. [
  46. {
  47. line: "'escaped single-quote: \\', normal double-quote: \"'",
  48. tokens: [
  49. { startIndex: 0, type: 'string.sql.rq' },
  50. { startIndex: 23, type: 'string.escape.rq' },
  51. { startIndex: 25, type: 'string.sql.rq' }
  52. ]
  53. }
  54. ],
  55. [
  56. {
  57. line: '("escaped \\" and \\\' and also not escaped \'.")',
  58. tokens: [
  59. { startIndex: 0, type: 'delimiter.parenthesis.rq' },
  60. { startIndex: 1, type: 'string.sql.rq' },
  61. { startIndex: 10, type: 'string.escape.rq' },
  62. { startIndex: 12, type: 'string.sql.rq' },
  63. { startIndex: 17, type: 'string.escape.rq' },
  64. { startIndex: 19, type: 'string.sql.rq' },
  65. { startIndex: 44, type: 'delimiter.parenthesis.rq' }
  66. ]
  67. }
  68. ],
  69. [
  70. {
  71. line: "'Invalid single string",
  72. tokens: [{ startIndex: 0, type: 'string.invalid.rq' }]
  73. }
  74. ],
  75. [
  76. {
  77. line: '"Invalid double string',
  78. tokens: [{ startIndex: 0, type: 'string.invalid.rq' }]
  79. }
  80. ],
  81. // identifiers, builtinFunctions and keywords
  82. [
  83. {
  84. line: 'PREFIX a: <http://www.w3.org/2000/10/annotation-ns#>',
  85. tokens: [
  86. { startIndex: 0, type: 'keyword.rq' },
  87. { startIndex: 6, type: 'white.rq' },
  88. { startIndex: 7, type: 'tag.rq' },
  89. { startIndex: 9, type: 'white.rq' },
  90. { startIndex: 10, type: 'tag.rq' }
  91. ]
  92. }
  93. ],
  94. [
  95. {
  96. line: 'SELECT DISTINCT ?name ?nick',
  97. tokens: [
  98. { startIndex: 0, type: 'keyword.rq' },
  99. { startIndex: 6, type: 'white.rq' },
  100. { startIndex: 7, type: 'keyword.rq' },
  101. { startIndex: 15, type: 'white.rq' },
  102. { startIndex: 16, type: 'identifier.rq' },
  103. { startIndex: 21, type: 'white.rq' },
  104. { startIndex: 22, type: 'identifier.rq' }
  105. ]
  106. }
  107. ],
  108. [
  109. {
  110. line: '(BGP [triple ?x foaf:nick ?nick])',
  111. tokens: [
  112. { startIndex: 0, type: 'delimiter.parenthesis.rq' },
  113. { startIndex: 1, type: 'identifier.rq' },
  114. { startIndex: 4, type: 'white.rq' },
  115. { startIndex: 5, type: 'delimiter.square.rq' },
  116. { startIndex: 6, type: 'identifier.rq' },
  117. { startIndex: 12, type: 'white.rq' },
  118. { startIndex: 13, type: 'identifier.rq' },
  119. { startIndex: 15, type: 'white.rq' },
  120. { startIndex: 16, type: 'tag.rq' },
  121. { startIndex: 25, type: 'white.rq' },
  122. { startIndex: 26, type: 'identifier.rq' },
  123. { startIndex: 31, type: 'delimiter.square.rq' },
  124. { startIndex: 32, type: 'delimiter.parenthesis.rq' }
  125. ]
  126. }
  127. ],
  128. [
  129. {
  130. line: 'SELECT*{ GRAPH :g1 { ?x } }',
  131. tokens: [
  132. { startIndex: 0, type: 'keyword.rq' },
  133. { startIndex: 6, type: 'operator.sql.rq' },
  134. { startIndex: 7, type: 'delimiter.curly.rq' },
  135. { startIndex: 8, type: 'white.rq' },
  136. { startIndex: 9, type: 'keyword.rq' },
  137. { startIndex: 14, type: 'white.rq' },
  138. { startIndex: 15, type: 'tag.rq' },
  139. { startIndex: 18, type: 'white.rq' },
  140. { startIndex: 19, type: 'delimiter.curly.rq' },
  141. { startIndex: 20, type: 'white.rq' },
  142. { startIndex: 21, type: 'identifier.rq' },
  143. { startIndex: 23, type: 'white.rq' },
  144. { startIndex: 24, type: 'delimiter.curly.rq' },
  145. { startIndex: 25, type: 'white.rq' },
  146. { startIndex: 26, type: 'delimiter.curly.rq' }
  147. ]
  148. }
  149. ],
  150. [
  151. {
  152. line: 'FILTER isBlank(?c)',
  153. tokens: [
  154. { startIndex: 0, type: 'keyword.rq' },
  155. { startIndex: 6, type: 'white.rq' },
  156. { startIndex: 7, type: 'predefined.sql.rq' },
  157. { startIndex: 14, type: 'delimiter.parenthesis.rq' },
  158. { startIndex: 15, type: 'identifier.rq' },
  159. { startIndex: 17, type: 'delimiter.parenthesis.rq' }
  160. ]
  161. }
  162. ],
  163. [
  164. {
  165. line: '"text"@en',
  166. tokens: [
  167. { startIndex: 0, type: 'string.sql.rq' },
  168. { startIndex: 6, type: 'metatag.html.rq' }
  169. ]
  170. }
  171. ]
  172. ]);