scala.test.ts 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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('scala', [
  8. // Comments - single line
  9. [{
  10. line: '//',
  11. tokens: [
  12. { startIndex: 0, type: 'comment.scala' }
  13. ]
  14. }],
  15. [{
  16. line: ' // a comment',
  17. tokens: [
  18. { startIndex: 0, type: '' },
  19. { startIndex: 4, type: 'comment.scala' }
  20. ]
  21. }],
  22. // Broken nested tokens due to invalid comment tokenization
  23. [{
  24. line: '/* //*/ a',
  25. tokens: [
  26. { startIndex: 0, type: 'comment.scala' },
  27. { startIndex: 7, type: '' },
  28. { startIndex: 8, type: 'identifier.scala' }
  29. ]
  30. }],
  31. [{
  32. line: '// a comment',
  33. tokens: [
  34. { startIndex: 0, type: 'comment.scala' }
  35. ]
  36. }],
  37. [{
  38. line: '//sticky comment',
  39. tokens: [
  40. { startIndex: 0, type: 'comment.scala' }
  41. ]
  42. }],
  43. [{
  44. line: '/almost a comment',
  45. tokens: [
  46. { startIndex: 0, type: 'delimiter.scala' },
  47. { startIndex: 1, type: 'identifier.scala' },
  48. { startIndex: 7, type: '' },
  49. { startIndex: 8, type: 'identifier.scala' },
  50. { startIndex: 9, type: '' },
  51. { startIndex: 10, type: 'identifier.scala' }
  52. ]
  53. }],
  54. [{
  55. line: '1 / 2; /* comment',
  56. tokens: [
  57. { startIndex: 0, type: 'number.scala' },
  58. { startIndex: 1, type: '' },
  59. { startIndex: 2, type: 'delimiter.scala' },
  60. { startIndex: 3, type: '' },
  61. { startIndex: 4, type: 'number.scala' },
  62. { startIndex: 5, type: 'delimiter.scala' },
  63. { startIndex: 6, type: '' },
  64. { startIndex: 7, type: 'comment.scala' }
  65. ]
  66. }],
  67. [{
  68. line: 'val x: Int = 1; // my comment // is a nice one',
  69. tokens: [
  70. { startIndex: 0, type: 'keyword.val.scala' },
  71. { startIndex: 3, type: '' },
  72. { startIndex: 4, type: 'identifier.scala' },
  73. { startIndex: 5, type: 'delimiter.scala' },
  74. { startIndex: 6, type: '' },
  75. { startIndex: 7, type: 'keyword.Int.scala' },
  76. { startIndex: 10, type: '' },
  77. { startIndex: 11, type: 'delimiter.scala' },
  78. { startIndex: 12, type: '' },
  79. { startIndex: 13, type: 'number.scala' },
  80. { startIndex: 14, type: 'delimiter.scala' },
  81. { startIndex: 15, type: '' },
  82. { startIndex: 16, type: 'comment.scala' }
  83. ]
  84. }],
  85. // Comments - range comment, single line
  86. [{
  87. line: '/* a simple comment */',
  88. tokens: [
  89. { startIndex: 0, type: 'comment.scala' }
  90. ]
  91. }],
  92. [{
  93. line: 'val x: Int = /* a simple comment */ 1;',
  94. tokens: [
  95. { startIndex: 0, type: 'keyword.val.scala' },
  96. { startIndex: 3, type: '' },
  97. { startIndex: 4, type: 'identifier.scala' },
  98. { startIndex: 5, type: 'delimiter.scala' },
  99. { startIndex: 6, type: '' },
  100. { startIndex: 7, type: 'keyword.Int.scala' },
  101. { startIndex: 10, type: '' },
  102. { startIndex: 11, type: 'delimiter.scala' },
  103. { startIndex: 12, type: '' },
  104. { startIndex: 13, type: 'comment.scala' },
  105. { startIndex: 35, type: '' },
  106. { startIndex: 36, type: 'number.scala' },
  107. { startIndex: 37, type: 'delimiter.scala' }
  108. ]
  109. }],
  110. [{
  111. line: 'val x: Int = /* a simple comment */ 1; */',
  112. tokens: [
  113. { startIndex: 0, type: 'keyword.val.scala' },
  114. { startIndex: 3, type: '' },
  115. { startIndex: 4, type: 'identifier.scala' },
  116. { startIndex: 5, type: 'delimiter.scala' },
  117. { startIndex: 6, type: '' },
  118. { startIndex: 7, type: 'keyword.Int.scala' },
  119. { startIndex: 10, type: '' },
  120. { startIndex: 11, type: 'delimiter.scala' },
  121. { startIndex: 12, type: '' },
  122. { startIndex: 13, type: 'comment.scala' },
  123. { startIndex: 35, type: '' },
  124. { startIndex: 36, type: 'number.scala' },
  125. { startIndex: 37, type: 'delimiter.scala' },
  126. { startIndex: 38, type: '' }
  127. ]
  128. }],
  129. [{
  130. line: 'x = /**/;',
  131. tokens: [
  132. { startIndex: 0, type: 'identifier.scala' },
  133. { startIndex: 1, type: '' },
  134. { startIndex: 2, type: 'delimiter.scala' },
  135. { startIndex: 3, type: '' },
  136. { startIndex: 4, type: 'comment.scala' },
  137. { startIndex: 8, type: 'delimiter.scala' }
  138. ]
  139. }],
  140. [{
  141. line: 'x = /*/;',
  142. tokens: [
  143. { startIndex: 0, type: 'identifier.scala' },
  144. { startIndex: 1, type: '' },
  145. { startIndex: 2, type: 'delimiter.scala' },
  146. { startIndex: 3, type: '' },
  147. { startIndex: 4, type: 'comment.scala' }
  148. ]
  149. }],
  150. // Comments - range comment, multiple lines
  151. [{
  152. line: '/* start of multiline comment',
  153. tokens: [
  154. { startIndex: 0, type: 'comment.scala' }
  155. ]
  156. }, {
  157. line: 'a comment between without a star',
  158. tokens: [
  159. { startIndex: 0, type: 'comment.scala' }
  160. ]
  161. }, {
  162. line: 'end of multiline comment*/',
  163. tokens: [
  164. { startIndex: 0, type: 'comment.scala' }
  165. ]
  166. }],
  167. [{
  168. line: 'val x: Int = /* start a comment',
  169. tokens: [
  170. { startIndex: 0, type: 'keyword.val.scala' },
  171. { startIndex: 3, type: '' },
  172. { startIndex: 4, type: 'identifier.scala' },
  173. { startIndex: 5, type: 'delimiter.scala' },
  174. { startIndex: 6, type: '' },
  175. { startIndex: 7, type: 'keyword.Int.scala' },
  176. { startIndex: 10, type: '' },
  177. { startIndex: 11, type: 'delimiter.scala' },
  178. { startIndex: 12, type: '' },
  179. { startIndex: 13, type: 'comment.scala' },
  180. ]
  181. }, {
  182. line: ' a ',
  183. tokens: [
  184. { startIndex: 0, type: 'comment.scala' },
  185. ]
  186. }, {
  187. line: 'and end it */ 2;',
  188. tokens: [
  189. { startIndex: 0, type: 'comment.scala' },
  190. { startIndex: 13, type: '' },
  191. { startIndex: 14, type: 'number.scala' },
  192. { startIndex: 15, type: 'delimiter.scala' }
  193. ]
  194. }],
  195. // Scala Doc, multiple lines
  196. [{
  197. line: '/** start of Scala Doc',
  198. tokens: [
  199. { startIndex: 0, type: 'comment.doc.scala' }
  200. ]
  201. }, {
  202. line: 'a comment between without a star',
  203. tokens: [
  204. { startIndex: 0, type: 'comment.doc.scala' }
  205. ]
  206. }, {
  207. line: 'end of multiline comment*/',
  208. tokens: [
  209. { startIndex: 0, type: 'comment.doc.scala' }
  210. ]
  211. }],
  212. // Keywords
  213. [{
  214. line: 'package test; object Program { def main(args: Array[String]): Unit = {} }',
  215. tokens: [
  216. { startIndex: 0, type: 'keyword.package.scala' },
  217. { startIndex: 7, type: '' },
  218. { startIndex: 8, type: 'identifier.scala' },
  219. { startIndex: 12, type: 'delimiter.scala' },
  220. { startIndex: 13, type: '' },
  221. { startIndex: 14, type: 'keyword.object.scala' },
  222. { startIndex: 20, type: '' },
  223. { startIndex: 21, type: 'identifier.scala' },
  224. { startIndex: 28, type: '' },
  225. { startIndex: 29, type: 'delimiter.curly.scala' },
  226. { startIndex: 30, type: '' },
  227. { startIndex: 31, type: 'keyword.def.scala' },
  228. { startIndex: 34, type: '' },
  229. { startIndex: 35, type: 'identifier.scala' },
  230. { startIndex: 39, type: 'delimiter.parenthesis.scala' },
  231. { startIndex: 40, type: 'identifier.scala' },
  232. { startIndex: 44, type: 'delimiter.scala' },
  233. { startIndex: 45, type: '' },
  234. { startIndex: 46, type: 'identifier.scala' },
  235. { startIndex: 51, type: 'delimiter.square.scala' },
  236. { startIndex: 52, type: 'identifier.scala' },
  237. { startIndex: 58, type: 'delimiter.square.scala' },
  238. { startIndex: 59, type: 'delimiter.parenthesis.scala' },
  239. { startIndex: 60, type: 'delimiter.scala' },
  240. { startIndex: 61, type: '' },
  241. { startIndex: 62, type: 'keyword.Unit.scala' },
  242. { startIndex: 66, type: '' },
  243. { startIndex: 67, type: 'delimiter.scala' },
  244. { startIndex: 68, type: '' },
  245. { startIndex: 69, type: 'delimiter.curly.scala' },
  246. { startIndex: 71, type: '' },
  247. { startIndex: 72, type: 'delimiter.curly.scala' }
  248. ]
  249. }],
  250. // Numbers
  251. [{
  252. line: '0',
  253. tokens: [
  254. { startIndex: 0, type: 'number.scala' }
  255. ]
  256. }],
  257. [{
  258. line: '0.10',
  259. tokens: [
  260. { startIndex: 0, type: 'number.float.scala' }
  261. ]
  262. }],
  263. [{
  264. line: '0x',
  265. tokens: [
  266. { startIndex: 0, type: 'number.scala' },
  267. { startIndex: 1, type: 'identifier.scala' }
  268. ]
  269. }],
  270. [{
  271. line: '0x123',
  272. tokens: [
  273. { startIndex: 0, type: 'number.hex.scala' }
  274. ]
  275. }],
  276. [{
  277. line: '0x5_2',
  278. tokens: [
  279. { startIndex: 0, type: 'number.hex.scala' }
  280. ]
  281. }],
  282. [{
  283. line: '10e3',
  284. tokens: [
  285. { startIndex: 0, type: 'number.float.scala' }
  286. ]
  287. }],
  288. [{
  289. line: '10f',
  290. tokens: [
  291. { startIndex: 0, type: 'number.float.scala' }
  292. ]
  293. }],
  294. [{
  295. line: '23.5',
  296. tokens: [
  297. { startIndex: 0, type: 'number.float.scala' }
  298. ]
  299. }],
  300. [{
  301. line: '23.5e3',
  302. tokens: [
  303. { startIndex: 0, type: 'number.float.scala' }
  304. ]
  305. }],
  306. [{
  307. line: '23.5e-3',
  308. tokens: [
  309. { startIndex: 0, type: 'number.float.scala' }
  310. ]
  311. }],
  312. [{
  313. line: '23.5E3',
  314. tokens: [
  315. { startIndex: 0, type: 'number.float.scala' }
  316. ]
  317. }],
  318. [{
  319. line: '23.5E-3',
  320. tokens: [
  321. { startIndex: 0, type: 'number.float.scala' }
  322. ]
  323. }],
  324. [{
  325. line: '23.5F',
  326. tokens: [
  327. { startIndex: 0, type: 'number.float.scala' }
  328. ]
  329. }],
  330. [{
  331. line: '23.5f',
  332. tokens: [
  333. { startIndex: 0, type: 'number.float.scala' }
  334. ]
  335. }],
  336. [{
  337. line: '23.5D',
  338. tokens: [
  339. { startIndex: 0, type: 'number.float.scala' }
  340. ]
  341. }],
  342. [{
  343. line: '23.5d',
  344. tokens: [
  345. { startIndex: 0, type: 'number.float.scala' }
  346. ]
  347. }],
  348. [{
  349. line: '1.72E3D',
  350. tokens: [
  351. { startIndex: 0, type: 'number.float.scala' }
  352. ]
  353. }],
  354. [{
  355. line: '1.72E3d',
  356. tokens: [
  357. { startIndex: 0, type: 'number.float.scala' }
  358. ]
  359. }],
  360. [{
  361. line: '1.72E-3d',
  362. tokens: [
  363. { startIndex: 0, type: 'number.float.scala' }
  364. ]
  365. }],
  366. [{
  367. line: '1.72e3D',
  368. tokens: [
  369. { startIndex: 0, type: 'number.float.scala' }
  370. ]
  371. }],
  372. [{
  373. line: '1.72e3d',
  374. tokens: [
  375. { startIndex: 0, type: 'number.float.scala' }
  376. ]
  377. }],
  378. [{
  379. line: '1.72e-3d',
  380. tokens: [
  381. { startIndex: 0, type: 'number.float.scala' }
  382. ]
  383. }],
  384. [{
  385. line: '23L',
  386. tokens: [
  387. { startIndex: 0, type: 'number.scala' }
  388. ]
  389. }],
  390. [{
  391. line: '23l',
  392. tokens: [
  393. { startIndex: 0, type: 'number.scala' }
  394. ]
  395. }],
  396. [{
  397. line: '5_2',
  398. tokens: [
  399. { startIndex: 0, type: 'number.scala' }
  400. ]
  401. }],
  402. [{
  403. line: '5_______2',
  404. tokens: [
  405. { startIndex: 0, type: 'number.scala' }
  406. ]
  407. }],
  408. [{
  409. line: '3_.1415F',
  410. tokens: [
  411. { startIndex: 0, type: 'number.scala' },
  412. { startIndex: 1, type: 'identifier.scala' },
  413. { startIndex: 2, type: 'delimiter.scala' },
  414. { startIndex: 3, type: 'number.float.scala' }
  415. ]
  416. }],
  417. [{
  418. line: '3._1415F',
  419. tokens: [
  420. { startIndex: 0, type: 'number.scala' },
  421. { startIndex: 1, type: 'delimiter.scala' },
  422. { startIndex: 2, type: 'identifier.scala' }
  423. ]
  424. }],
  425. [{
  426. line: '999_99_9999_L',
  427. tokens: [
  428. { startIndex: 0, type: 'number.scala' },
  429. { startIndex: 11, type: 'identifier.scala' }
  430. ]
  431. }],
  432. [{
  433. line: '52_',
  434. tokens: [
  435. { startIndex: 0, type: 'number.scala' },
  436. { startIndex: 2, type: 'identifier.scala' }
  437. ]
  438. }],
  439. [{
  440. line: '0_x52',
  441. tokens: [
  442. { startIndex: 0, type: 'number.scala' },
  443. { startIndex: 1, type: 'identifier.scala' }
  444. ]
  445. }],
  446. [{
  447. line: '0x_52',
  448. tokens: [
  449. { startIndex: 0, type: 'number.scala' },
  450. { startIndex: 1, type: 'identifier.scala' }
  451. ]
  452. }],
  453. [{
  454. line: '0x52_',
  455. tokens: [
  456. { startIndex: 0, type: 'number.hex.scala' },
  457. { startIndex: 4, type: 'identifier.scala' }
  458. ]
  459. }],
  460. [{
  461. line: '23.5L',
  462. tokens: [
  463. { startIndex: 0, type: 'number.float.scala' },
  464. { startIndex: 4, type: 'identifier.scala' }
  465. ]
  466. }],
  467. [{
  468. line: '0+0',
  469. tokens: [
  470. { startIndex: 0, type: 'number.scala' },
  471. { startIndex: 1, type: 'delimiter.scala' },
  472. { startIndex: 2, type: 'number.scala' }
  473. ]
  474. }],
  475. [{
  476. line: '100+10',
  477. tokens: [
  478. { startIndex: 0, type: 'number.scala' },
  479. { startIndex: 3, type: 'delimiter.scala' },
  480. { startIndex: 4, type: 'number.scala' }
  481. ]
  482. }],
  483. [{
  484. line: '0 + 0',
  485. tokens: [
  486. { startIndex: 0, type: 'number.scala' },
  487. { startIndex: 1, type: '' },
  488. { startIndex: 2, type: 'delimiter.scala' },
  489. { startIndex: 3, type: '' },
  490. { startIndex: 4, type: 'number.scala' }
  491. ]
  492. }],
  493. // single line Strings
  494. [{
  495. line: 'val s: String = "I\'m a Scala String";',
  496. tokens: [
  497. { startIndex: 0, type: 'keyword.val.scala' },
  498. { startIndex: 3, type: '' },
  499. { startIndex: 4, type: 'identifier.scala' },
  500. { startIndex: 5, type: 'delimiter.scala' },
  501. { startIndex: 6, type: '' },
  502. { startIndex: 7, type: 'identifier.scala' },
  503. { startIndex: 13, type: '' },
  504. { startIndex: 14, type: 'delimiter.scala' },
  505. { startIndex: 15, type: '' },
  506. { startIndex: 16, type: 'string.scala' },
  507. { startIndex: 36, type: 'delimiter.scala' }
  508. ]
  509. }],
  510. [{
  511. line: 'val s: String = "concatenated" + " String" ;',
  512. tokens: [
  513. { startIndex: 0, type: 'keyword.val.scala' },
  514. { startIndex: 3, type: '' },
  515. { startIndex: 4, type: 'identifier.scala' },
  516. { startIndex: 5, type: 'delimiter.scala' },
  517. { startIndex: 6, type: '' },
  518. { startIndex: 7, type: 'identifier.scala' },
  519. { startIndex: 13, type: '' },
  520. { startIndex: 14, type: 'delimiter.scala' },
  521. { startIndex: 15, type: '' },
  522. { startIndex: 16, type: 'string.scala' },
  523. { startIndex: 30, type: '' },
  524. { startIndex: 31, type: 'delimiter.scala' },
  525. { startIndex: 32, type: '' },
  526. { startIndex: 33, type: 'string.scala' },
  527. { startIndex: 42, type: '' },
  528. { startIndex: 43, type: 'delimiter.scala' }
  529. ]
  530. }],
  531. [{
  532. line: '"quote in a string"',
  533. tokens: [
  534. { startIndex: 0, type: 'string.scala' }
  535. ]
  536. }],
  537. [{
  538. line: '"escaping \\"quotes\\" is cool"',
  539. tokens: [
  540. { startIndex: 0, type: 'string.scala' },
  541. { startIndex: 10, type: 'string.escape.scala' },
  542. { startIndex: 12, type: 'string.scala' },
  543. { startIndex: 18, type: 'string.escape.scala' },
  544. { startIndex: 20, type: 'string.scala' }
  545. ]
  546. }],
  547. [{
  548. line: '"\\"',
  549. tokens: [
  550. { startIndex: 0, type: 'string.invalid.scala' }
  551. ]
  552. }],
  553. // Annotations
  554. [{
  555. line: '@',
  556. tokens: [
  557. { startIndex: 0, type: '' }
  558. ]
  559. }],
  560. [{
  561. line: '@uncheckedStable',
  562. tokens: [
  563. { startIndex: 0, type: 'annotation.scala' }
  564. ]
  565. }],
  566. [{
  567. line: '@silent("deprecated")',
  568. tokens: [
  569. { startIndex: 0, type: 'annotation.scala' },
  570. { startIndex: 7, type: 'delimiter.parenthesis.scala' },
  571. { startIndex: 8, type: 'string.scala' },
  572. { startIndex: 20, type: 'delimiter.parenthesis.scala' }
  573. ]
  574. }],
  575. [{
  576. line: '@ AnnotationWithKeywordAfter private',
  577. tokens: [
  578. { startIndex: 0, type: 'annotation.scala' },
  579. { startIndex: 28, type: '' },
  580. { startIndex: 29, type: 'keyword.private.scala' }
  581. ]
  582. }]
  583. ]);