1
0

mysql.test.ts 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554
  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('mysql', [
  8. // Comments
  9. [{
  10. line: '-- a comment',
  11. tokens: [
  12. { startIndex: 0, type: 'comment.sql' }
  13. ]
  14. }],
  15. [{
  16. line: '---sticky -- comment',
  17. tokens: [
  18. { startIndex: 0, type: 'comment.sql' }
  19. ]
  20. }],
  21. [{
  22. line: '-almost a comment',
  23. tokens: [
  24. { startIndex: 0, type: 'operator.sql' },
  25. { startIndex: 1, type: 'identifier.sql' },
  26. { startIndex: 7, type: 'white.sql' },
  27. { startIndex: 8, type: 'identifier.sql' },
  28. { startIndex: 9, type: 'white.sql' },
  29. { startIndex: 10, type: 'keyword.sql' }
  30. ]
  31. }],
  32. [{
  33. line: '/* a full line comment */',
  34. tokens: [
  35. { startIndex: 0, type: 'comment.quote.sql' },
  36. { startIndex: 2, type: 'comment.sql' },
  37. { startIndex: 23, type: 'comment.quote.sql' }
  38. ]
  39. }],
  40. [{
  41. line: '/* /// *** /// */',
  42. tokens: [
  43. { startIndex: 0, type: 'comment.quote.sql' },
  44. { startIndex: 2, type: 'comment.sql' },
  45. { startIndex: 15, type: 'comment.quote.sql' }
  46. ]
  47. }],
  48. [{
  49. line: '# comment',
  50. tokens: [
  51. { startIndex: 0, type: 'comment.sql' }
  52. ]
  53. }],
  54. [{
  55. line: 'declare @x int = /* a simple comment */ 1;',
  56. tokens: [
  57. { startIndex: 0, type: 'keyword.sql' },
  58. { startIndex: 7, type: 'white.sql' },
  59. { startIndex: 8, type: 'identifier.sql' },
  60. { startIndex: 10, type: 'white.sql' },
  61. { startIndex: 11, type: 'keyword.sql' },
  62. { startIndex: 14, type: 'white.sql' },
  63. { startIndex: 15, type: 'operator.sql' },
  64. { startIndex: 16, type: 'white.sql' },
  65. { startIndex: 17, type: 'comment.quote.sql' },
  66. { startIndex: 19, type: 'comment.sql' },
  67. { startIndex: 37, type: 'comment.quote.sql' },
  68. { startIndex: 39, type: 'white.sql' },
  69. { startIndex: 40, type: 'number.sql' },
  70. { startIndex: 41, type: 'delimiter.sql' }
  71. ]
  72. }],
  73. // Not supporting nested comments, as nested comments seem to not be standard?
  74. // i.e. http://stackoverflow.com/questions/728172/are-there-multiline-comment-delimiters-in-sql-that-are-vendor-agnostic
  75. [{
  76. line: '@x=/* a /* nested comment 1*/;',
  77. tokens: [
  78. { startIndex: 0, type: 'identifier.sql' },
  79. { startIndex: 2, type: 'operator.sql' },
  80. { startIndex: 3, type: 'comment.quote.sql' },
  81. { startIndex: 5, type: 'comment.sql' },
  82. { startIndex: 28, type: 'comment.quote.sql' },
  83. { startIndex: 30, type: 'delimiter.sql' }
  84. ]
  85. }],
  86. [{
  87. line: '@x=/* another comment */ 1*/;',
  88. tokens: [
  89. { startIndex: 0, type: 'identifier.sql' },
  90. { startIndex: 2, type: 'operator.sql' },
  91. { startIndex: 3, type: 'comment.quote.sql' },
  92. { startIndex: 5, type: 'comment.sql' },
  93. { startIndex: 22, type: 'comment.quote.sql' },
  94. { startIndex: 24, type: 'white.sql' },
  95. { startIndex: 25, type: 'number.sql' },
  96. { startIndex: 26, type: 'operator.sql' },
  97. { startIndex: 28, type: 'delimiter.sql' }
  98. ]
  99. }],
  100. [{
  101. line: '@x=/*/;',
  102. tokens: [
  103. { startIndex: 0, type: 'identifier.sql' },
  104. { startIndex: 2, type: 'operator.sql' },
  105. { startIndex: 3, type: 'comment.quote.sql' },
  106. { startIndex: 5, type: 'comment.sql' }
  107. ]
  108. }],
  109. // Numbers
  110. [{
  111. line: '123',
  112. tokens: [
  113. { startIndex: 0, type: 'number.sql' }
  114. ]
  115. }],
  116. [{
  117. line: '-123',
  118. tokens: [
  119. { startIndex: 0, type: 'operator.sql' },
  120. { startIndex: 1, type: 'number.sql' }
  121. ]
  122. }],
  123. [{
  124. line: '0xaBc123',
  125. tokens: [
  126. { startIndex: 0, type: 'number.sql' }
  127. ]
  128. }],
  129. [{
  130. line: '0XaBc123',
  131. tokens: [
  132. { startIndex: 0, type: 'number.sql' }
  133. ]
  134. }],
  135. [{
  136. line: '0x',
  137. tokens: [
  138. { startIndex: 0, type: 'number.sql' }
  139. ]
  140. }],
  141. [{
  142. line: '0x0',
  143. tokens: [
  144. { startIndex: 0, type: 'number.sql' }
  145. ]
  146. }],
  147. [{
  148. line: '0xAB_CD',
  149. tokens: [
  150. { startIndex: 0, type: 'number.sql' },
  151. { startIndex: 4, type: 'identifier.sql' }
  152. ]
  153. }],
  154. [{
  155. line: '$',
  156. tokens: [
  157. { startIndex: 0, type: 'number.sql' }
  158. ]
  159. }],
  160. [{
  161. line: '$-123',
  162. tokens: [
  163. { startIndex: 0, type: 'number.sql' }
  164. ]
  165. }],
  166. [{
  167. line: '$-+-123',
  168. tokens: [
  169. { startIndex: 0, type: 'number.sql' }
  170. ]
  171. }],
  172. [{
  173. line: '$123.5678',
  174. tokens: [
  175. { startIndex: 0, type: 'number.sql' }
  176. ]
  177. }],
  178. [{
  179. line: '$0.99',
  180. tokens: [
  181. { startIndex: 0, type: 'number.sql' }
  182. ]
  183. }],
  184. [{
  185. line: '$.99',
  186. tokens: [
  187. { startIndex: 0, type: 'number.sql' }
  188. ]
  189. }],
  190. [{
  191. line: '$99.',
  192. tokens: [
  193. { startIndex: 0, type: 'number.sql' }
  194. ]
  195. }],
  196. [{
  197. line: '$0.',
  198. tokens: [
  199. { startIndex: 0, type: 'number.sql' }
  200. ]
  201. }],
  202. [{
  203. line: '$.0',
  204. tokens: [
  205. { startIndex: 0, type: 'number.sql' }
  206. ]
  207. }],
  208. [{
  209. line: '.',
  210. tokens: [
  211. { startIndex: 0, type: 'delimiter.sql' }
  212. ]
  213. }],
  214. [{
  215. line: '123',
  216. tokens: [
  217. { startIndex: 0, type: 'number.sql' }
  218. ]
  219. }],
  220. [{
  221. line: '123.5678',
  222. tokens: [
  223. { startIndex: 0, type: 'number.sql' }
  224. ]
  225. }],
  226. [{
  227. line: '0.99',
  228. tokens: [
  229. { startIndex: 0, type: 'number.sql' }
  230. ]
  231. }],
  232. [{
  233. line: '.99',
  234. tokens: [
  235. { startIndex: 0, type: 'number.sql' }
  236. ]
  237. }],
  238. [{
  239. line: '99.',
  240. tokens: [
  241. { startIndex: 0, type: 'number.sql' }
  242. ]
  243. }],
  244. [{
  245. line: '0.',
  246. tokens: [
  247. { startIndex: 0, type: 'number.sql' }
  248. ]
  249. }],
  250. [{
  251. line: '.0',
  252. tokens: [
  253. { startIndex: 0, type: 'number.sql' }
  254. ]
  255. }],
  256. [{
  257. line: '1E-2',
  258. tokens: [
  259. { startIndex: 0, type: 'number.sql' }
  260. ]
  261. }],
  262. [{
  263. line: '1E+2',
  264. tokens: [
  265. { startIndex: 0, type: 'number.sql' }
  266. ]
  267. }],
  268. [{
  269. line: '1E2',
  270. tokens: [
  271. { startIndex: 0, type: 'number.sql' }
  272. ]
  273. }],
  274. [{
  275. line: '0.1E2',
  276. tokens: [
  277. { startIndex: 0, type: 'number.sql' }
  278. ]
  279. }],
  280. [{
  281. line: '1.E2',
  282. tokens: [
  283. { startIndex: 0, type: 'number.sql' }
  284. ]
  285. }],
  286. [{
  287. line: '.1E2',
  288. tokens: [
  289. { startIndex: 0, type: 'number.sql' }
  290. ]
  291. }],
  292. // Identifiers
  293. [{
  294. line: 'declare `abc 321`;',
  295. tokens: [
  296. { startIndex: 0, type: 'keyword.sql' },
  297. { startIndex: 7, type: 'white.sql' },
  298. { startIndex: 8, type: 'identifier.quote.sql' },
  299. { startIndex: 9, type: 'identifier.sql' },
  300. { startIndex: 16, type: 'identifier.quote.sql' },
  301. { startIndex: 17, type: 'delimiter.sql' }
  302. ]
  303. }],
  304. [{
  305. line: '`abc`` 321 `` xyz`',
  306. tokens: [
  307. { startIndex: 0, type: 'identifier.quote.sql' },
  308. { startIndex: 1, type: 'identifier.sql' },
  309. { startIndex: 17, type: 'identifier.quote.sql' }
  310. ]
  311. }],
  312. [{
  313. line: '`abc',
  314. tokens: [
  315. { startIndex: 0, type: 'identifier.quote.sql' },
  316. { startIndex: 1, type: 'identifier.sql' }
  317. ]
  318. }],
  319. [{
  320. line: 'declare `abc 321`;',
  321. tokens: [
  322. { startIndex: 0, type: 'keyword.sql' },
  323. { startIndex: 7, type: 'white.sql' },
  324. { startIndex: 8, type: 'identifier.quote.sql' },
  325. { startIndex: 9, type: 'identifier.sql' },
  326. { startIndex: 16, type: 'identifier.quote.sql' },
  327. { startIndex: 17, type: 'delimiter.sql' }
  328. ]
  329. }],
  330. [{
  331. line: '`abc`` 321 `` xyz`',
  332. tokens: [
  333. { startIndex: 0, type: 'identifier.quote.sql' },
  334. { startIndex: 1, type: 'identifier.sql' },
  335. { startIndex: 17, type: 'identifier.quote.sql' }
  336. ]
  337. }],
  338. [{
  339. line: '`abc',
  340. tokens: [
  341. { startIndex: 0, type: 'identifier.quote.sql' },
  342. { startIndex: 1, type: 'identifier.sql' }
  343. ]
  344. }],
  345. [{
  346. line: 'int',
  347. tokens: [
  348. { startIndex: 0, type: 'keyword.sql' }
  349. ]
  350. }],
  351. [{
  352. line: '`int`',
  353. tokens: [
  354. { startIndex: 0, type: 'identifier.quote.sql' },
  355. { startIndex: 1, type: 'identifier.sql' },
  356. { startIndex: 4, type: 'identifier.quote.sql' }
  357. ]
  358. }],
  359. // Strings
  360. [{
  361. line: 'declare @x=\'a string\';',
  362. tokens: [
  363. { startIndex: 0, type: 'keyword.sql' },
  364. { startIndex: 7, type: 'white.sql' },
  365. { startIndex: 8, type: 'identifier.sql' },
  366. { startIndex: 10, type: 'operator.sql' },
  367. { startIndex: 11, type: 'string.sql' },
  368. { startIndex: 21, type: 'delimiter.sql' }
  369. ]
  370. }],
  371. [{
  372. line: 'declare @x="a string";',
  373. tokens: [
  374. { startIndex: 0, type: 'keyword.sql' },
  375. { startIndex: 7, type: 'white.sql' },
  376. { startIndex: 8, type: 'identifier.sql' },
  377. { startIndex: 10, type: 'operator.sql' },
  378. { startIndex: 11, type: 'string.double.sql' },
  379. { startIndex: 21, type: 'delimiter.sql' }
  380. ]
  381. }],
  382. [{
  383. line: '\'a \'\' string with quotes\'',
  384. tokens: [
  385. { startIndex: 0, type: 'string.sql' },
  386. ]
  387. }],
  388. [{
  389. line: '"a "" string with quotes"',
  390. tokens: [
  391. { startIndex: 0, type: 'string.double.sql' },
  392. ]
  393. }],
  394. [{
  395. line: '\'a " string with quotes\'',
  396. tokens: [
  397. { startIndex: 0, type: 'string.sql' },
  398. ]
  399. }],
  400. [{
  401. line: '"a ` string with quotes"',
  402. tokens: [
  403. { startIndex: 0, type: 'string.double.sql' },
  404. ]
  405. }],
  406. [{
  407. line: '\'a -- string with comment\'',
  408. tokens: [
  409. { startIndex: 0, type: 'string.sql' },
  410. ]
  411. }],
  412. [{
  413. line: '"a -- string with comment"',
  414. tokens: [
  415. { startIndex: 0, type: 'string.double.sql' },
  416. ]
  417. }],
  418. [{
  419. line: '\'a endless string',
  420. tokens: [
  421. { startIndex: 0, type: 'string.sql' },
  422. ]
  423. }],
  424. [{
  425. line: '"a endless string',
  426. tokens: [
  427. { startIndex: 0, type: 'string.double.sql' },
  428. ]
  429. }],
  430. // Operators
  431. [{
  432. line: 'SET @x=@x+1',
  433. tokens: [
  434. { startIndex: 0, type: 'keyword.sql' },
  435. { startIndex: 3, type: 'white.sql' },
  436. { startIndex: 4, type: 'identifier.sql' },
  437. { startIndex: 6, type: 'operator.sql' },
  438. { startIndex: 7, type: 'identifier.sql' },
  439. { startIndex: 9, type: 'operator.sql' },
  440. { startIndex: 10, type: 'number.sql' }
  441. ]
  442. }],
  443. [{
  444. line: '@x^=@x',
  445. tokens: [
  446. { startIndex: 0, type: 'identifier.sql' },
  447. { startIndex: 2, type: 'operator.sql' },
  448. { startIndex: 4, type: 'identifier.sql' }
  449. ]
  450. }],
  451. [{
  452. line: 'WHERE myfield IS NOT NULL',
  453. tokens: [
  454. { startIndex: 0, type: 'keyword.sql' },
  455. { startIndex: 5, type: 'white.sql' },
  456. { startIndex: 6, type: 'identifier.sql' },
  457. { startIndex: 13, type: 'white.sql' },
  458. { startIndex: 14, type: 'operator.sql' },
  459. { startIndex: 16, type: 'white.sql' },
  460. { startIndex: 17, type: 'operator.sql' },
  461. { startIndex: 20, type: 'white.sql' },
  462. { startIndex: 21, type: 'operator.sql' }
  463. ]
  464. }],
  465. [{
  466. line: 'SELECT * FROM tbl WHERE MyColumn IN (1,2)',
  467. tokens: [
  468. { startIndex: 0, type: 'keyword.sql' },
  469. { startIndex: 6, type: 'white.sql' },
  470. { startIndex: 7, type: 'operator.sql' },
  471. { startIndex: 8, type: 'white.sql' },
  472. { startIndex: 9, type: 'keyword.sql' },
  473. { startIndex: 13, type: 'white.sql' },
  474. { startIndex: 14, type: 'identifier.sql' },
  475. { startIndex: 17, type: 'white.sql' },
  476. { startIndex: 18, type: 'keyword.sql' },
  477. { startIndex: 23, type: 'white.sql' },
  478. { startIndex: 24, type: 'identifier.sql' },
  479. { startIndex: 32, type: 'white.sql' },
  480. { startIndex: 33, type: 'operator.sql' },
  481. { startIndex: 35, type: 'white.sql' },
  482. { startIndex: 36, type: 'delimiter.parenthesis.sql' },
  483. { startIndex: 37, type: 'number.sql' },
  484. { startIndex: 38, type: 'delimiter.sql' },
  485. { startIndex: 39, type: 'number.sql' },
  486. { startIndex: 40, type: 'delimiter.parenthesis.sql' }
  487. ]
  488. }]
  489. ]);