mysql.test.ts 10 KB

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