msdax.test.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370
  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 './testRunner';
  7. testTokenization('msdax', [
  8. // Comments
  9. [{
  10. line: '// a comment',
  11. tokens: [
  12. { startIndex: 0, type: 'comment.msdax' }
  13. ]}],
  14. [{
  15. line: '-almost a comment',
  16. tokens: [
  17. { startIndex: 0, type: 'operator.msdax' },
  18. { startIndex: 1, type: 'identifier.msdax' },
  19. { startIndex: 7, type: 'white.msdax' },
  20. { startIndex: 8, type: 'identifier.msdax' },
  21. { startIndex: 9, type: 'white.msdax' },
  22. { startIndex: 10, type: 'identifier.msdax' }
  23. ]}],
  24. [{
  25. line: '/* a full line comment */',
  26. tokens: [
  27. { startIndex: 0, type: 'comment.quote.msdax' },
  28. { startIndex: 2, type: 'comment.msdax' },
  29. { startIndex: 23, type: 'comment.quote.msdax' }
  30. ]}],
  31. [{
  32. line: '/* /// *** /// */',
  33. tokens: [
  34. { startIndex: 0, type: 'comment.quote.msdax' },
  35. { startIndex: 2, type: 'comment.msdax' },
  36. { startIndex: 15, type: 'comment.quote.msdax' }
  37. ]}],
  38. [{
  39. line: 'define measure x = /* a simple comment */ 1;',
  40. tokens: [
  41. { startIndex: 0, type: 'keyword.msdax' },
  42. { startIndex: 6, type: 'white.msdax' },
  43. { startIndex: 7, type: 'keyword.msdax' },
  44. { startIndex: 14, type: 'white.msdax' },
  45. { startIndex: 15, type: 'identifier.msdax' },
  46. { startIndex: 16, type: 'white.msdax' },
  47. { startIndex: 17, type: 'operator.msdax' },
  48. { startIndex: 18, type: 'white.msdax' },
  49. { startIndex: 19, type: 'comment.quote.msdax' },
  50. { startIndex: 21, type: 'comment.msdax' },
  51. { startIndex: 39, type: 'comment.quote.msdax' },
  52. { startIndex: 41, type: 'white.msdax' },
  53. { startIndex: 42, type: 'number.msdax' },
  54. { startIndex: 43, type: 'delimiter.msdax' }
  55. ]}],
  56. // Numbers
  57. [{
  58. line: '123',
  59. tokens: [
  60. { startIndex: 0, type: 'number.msdax' }
  61. ]}],
  62. [{
  63. line: '-123',
  64. tokens: [
  65. { startIndex: 0, type: 'operator.msdax' },
  66. { startIndex: 1, type: 'number.msdax' }
  67. ]}],
  68. [{
  69. line: '0xaBc123',
  70. tokens: [
  71. { startIndex: 0, type: 'number.msdax' }
  72. ]}],
  73. [{
  74. line: '0XaBc123',
  75. tokens: [
  76. { startIndex: 0, type: 'number.msdax' }
  77. ]}],
  78. [{
  79. line: '0x',
  80. tokens: [
  81. { startIndex: 0, type: 'number.msdax' }
  82. ]}],
  83. [{
  84. line: '0x0',
  85. tokens: [
  86. { startIndex: 0, type: 'number.msdax' }
  87. ]}],
  88. [{
  89. line: '0xAB_CD',
  90. tokens: [
  91. { startIndex: 0, type: 'number.msdax' },
  92. { startIndex: 4, type: 'identifier.msdax' }
  93. ]}],
  94. [{
  95. line: '.',
  96. tokens: [
  97. { startIndex: 0, type: 'delimiter.msdax' }
  98. ]}],
  99. [{
  100. line: '123',
  101. tokens: [
  102. { startIndex: 0, type: 'number.msdax' }
  103. ]}],
  104. [{
  105. line: '123.5678',
  106. tokens: [
  107. { startIndex: 0, type: 'number.msdax' }
  108. ]}],
  109. [{
  110. line: '0.99',
  111. tokens: [
  112. { startIndex: 0, type: 'number.msdax' }
  113. ]}],
  114. [{
  115. line: '.99',
  116. tokens: [
  117. { startIndex: 0, type: 'number.msdax' }
  118. ]}],
  119. [{
  120. line: '99.',
  121. tokens: [
  122. { startIndex: 0, type: 'number.msdax' }
  123. ]}],
  124. [{
  125. line: '0.',
  126. tokens: [
  127. { startIndex: 0, type: 'number.msdax' }
  128. ]}],
  129. [{
  130. line: '.0',
  131. tokens: [
  132. { startIndex: 0, type: 'number.msdax' }
  133. ]}],
  134. [{
  135. line: '1E-2',
  136. tokens: [
  137. { startIndex: 0, type: 'number.msdax' }
  138. ]}],
  139. [{
  140. line: '1E+2',
  141. tokens: [
  142. { startIndex: 0, type: 'number.msdax' }
  143. ]}],
  144. [{
  145. line: '1E2',
  146. tokens: [
  147. { startIndex: 0, type: 'number.msdax' }
  148. ]}],
  149. [{
  150. line: '0.1E2',
  151. tokens: [
  152. { startIndex: 0, type: 'number.msdax' }
  153. ]}],
  154. [{
  155. line: '1.E2',
  156. tokens: [
  157. { startIndex: 0, type: 'number.msdax' }
  158. ]}],
  159. [{
  160. line: '.1E2',
  161. tokens: [
  162. { startIndex: 0, type: 'number.msdax' }
  163. ]}],
  164. // Identifiers
  165. [{
  166. line: '_abc01',
  167. tokens: [
  168. { startIndex: 0, type: 'identifier.msdax' }
  169. ]}],
  170. [{
  171. line: 'abc01',
  172. tokens: [
  173. { startIndex: 0, type: 'identifier.msdax' }
  174. ]}],
  175. [{
  176. line: 'evaluate filter',
  177. tokens: [
  178. { startIndex: 0, type: 'keyword.msdax' },
  179. { startIndex: 8, type: 'white.msdax' },
  180. { startIndex: 9, type: 'keyword.msdax' }
  181. ]}],
  182. [{
  183. line: '[abc[[ 321 ]] xyz]',
  184. tokens: [
  185. { startIndex: 0, type: 'identifier.quote.msdax' },
  186. { startIndex: 1, type: 'identifier.msdax' },
  187. { startIndex: 17, type: 'identifier.quote.msdax' }
  188. ]}],
  189. [{
  190. line: '[abc',
  191. tokens: [
  192. { startIndex: 0, type: 'identifier.quote.msdax' },
  193. { startIndex: 1, type: 'identifier.msdax' }
  194. ]}],
  195. [{
  196. line: 'define measure \'abc\'[def]',
  197. tokens: [
  198. { startIndex: 0, type: 'keyword.msdax' },
  199. { startIndex: 6, type: 'white.msdax' },
  200. { startIndex: 7, type: 'keyword.msdax' },
  201. { startIndex: 14, type: 'white.msdax' },
  202. { startIndex: 15, type: 'identifier.quote.msdax' },
  203. { startIndex: 16, type: 'identifier.msdax' },
  204. { startIndex: 19, type: 'identifier.quote.msdax' },
  205. { startIndex: 21, type: 'identifier.msdax' }
  206. { startIndex: 24, type: 'identifier.quote.msdax' }
  207. ]}],
  208. [{
  209. line: 'int',
  210. tokens: [
  211. { startIndex: 0, type: 'keyword.msdax' }
  212. ]}],
  213. [{
  214. line: '[int]',
  215. tokens: [
  216. { startIndex: 0, type: 'identifier.quote.msdax' },
  217. { startIndex: 1, type: 'identifier.msdax' },
  218. { startIndex: 4, type: 'identifier.quote.msdax' }
  219. ]}],
  220. // Strings
  221. [{
  222. line: '"abc"" 321 "" xyz"',
  223. tokens: [
  224. { startIndex: 0, type: 'string.msdax' }
  225. ]}],
  226. [{
  227. line: 'define var x=\"a string\"',
  228. tokens: [
  229. { startIndex: 0, type: 'keyword.msdax' },
  230. { startIndex: 6, type: 'white.msdax' },
  231. { startIndex: 7, type: 'keyword.msdax' },
  232. { startIndex: 10, type: 'white.msdax' },
  233. { startIndex: 11, type: 'identifier.msdax' },
  234. { startIndex: 12, type: 'operator.msdax' },
  235. { startIndex: 13, type: 'string.msdax' }
  236. ]}],
  237. [{
  238. line: '"a "" string with quotes"',
  239. tokens: [
  240. { startIndex: 0, type: 'string.msdax' },
  241. ]}],
  242. [{
  243. line: '"a // string with comment"',
  244. tokens: [
  245. { startIndex: 0, type: 'string.msdax' },
  246. ]}],
  247. [{
  248. line: 'N"a unicode string"',
  249. tokens: [
  250. { startIndex: 0, type: 'string.msdax' },
  251. ]}],
  252. [{
  253. line: '"a endless string',
  254. tokens: [
  255. { startIndex: 0, type: 'string.msdax' },
  256. ]}],
  257. // Operators
  258. [{
  259. line: 'define var x=1+3',
  260. tokens: [
  261. { startIndex: 0, type: 'keyword.msdax' },
  262. { startIndex: 6, type: 'white.msdax' },
  263. { startIndex: 7, type: 'keyword.msdax' },
  264. { startIndex: 10, type: 'white.msdax' },
  265. { startIndex: 11, type: 'identifier.msdax' },
  266. { startIndex: 12, type: 'operator.msdax' },
  267. { startIndex: 13, type: 'number.msdax' },
  268. { startIndex: 14, type: 'operator.msdax' },
  269. { startIndex: 15, type: 'number.msdax' }
  270. ]}],
  271. [{
  272. line: 'define var x=1^+abc',
  273. tokens: [
  274. { startIndex: 0, type: 'keyword.msdax' },
  275. { startIndex: 6, type: 'white.msdax' },
  276. { startIndex: 7, type: 'keyword.msdax' },
  277. { startIndex: 10, type: 'white.msdax' },
  278. { startIndex: 11, type: 'identifier.msdax' },
  279. { startIndex: 12, type: 'operator.msdax' },
  280. { startIndex: 13, type: 'number.msdax' },
  281. { startIndex: 14, type: 'operator.msdax' },
  282. { startIndex: 16, type: 'identifier.msdax' }
  283. ]}],
  284. // Realistic queries and expressions
  285. [{
  286. line: 'EVALUATE \'Products\' ORDER BY [Product Id] DESC',
  287. tokens: [
  288. { startIndex: 0, type: 'keyword.msdax' },
  289. { startIndex: 8, type: 'white.msdax' },
  290. { startIndex: 9, type: 'identifier.quote.msdax' },
  291. { startIndex: 10, type: 'identifier.msdax' },
  292. { startIndex: 18, type: 'identifier.quote.msdax' },
  293. { startIndex: 19, type: 'white.msdax' },
  294. { startIndex: 20, type: 'keyword.msdax' },
  295. { startIndex: 25, type: 'white.msdax' },
  296. { startIndex: 26, type: 'keyword.msdax' },
  297. { startIndex: 28, type: 'white.msdax' },
  298. { startIndex: 29, type: 'identifier.quote.msdax' },
  299. { startIndex: 30, type: 'identifier.msdax' },
  300. { startIndex: 40, type: 'identifier.quote.msdax' },
  301. { startIndex: 41, type: 'white.msdax' },
  302. { startIndex: 42, type: 'keyword.msdax' }
  303. ]}],
  304. [{
  305. line: 'DATATABLE("Price", STRING, {{"Low"},{"Medium"}})',
  306. tokens: [
  307. { startIndex: 0, type: 'keyword.msdax' },
  308. { startIndex: 9, type: 'delimiter.parenthesis.msdax' },
  309. { startIndex: 10, type: 'string.msdax' },
  310. { startIndex: 17, type: 'delimiter.msdax' },
  311. { startIndex: 18, type: 'white.msdax' },
  312. { startIndex: 19, type: 'keyword.msdax' },
  313. { startIndex: 25, type: 'delimiter.msdax' },
  314. { startIndex: 26, type: 'white.msdax' },
  315. { startIndex: 27, type: 'delimiter.brackets.msdax' },
  316. { startIndex: 29, type: 'string.msdax' },
  317. { startIndex: 34, type: 'delimiter.brackets.msdax' },
  318. { startIndex: 35, type: 'delimiter.msdax' },
  319. { startIndex: 36, type: 'delimiter.brackets.msdax' },
  320. { startIndex: 37, type: 'string.msdax' },
  321. { startIndex: 45, type: 'delimiter.brackets.msdax' },
  322. { startIndex: 47, type: 'delimiter.parenthesis.msdax' }
  323. ]}]
  324. ]);