fsharp.test.ts 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491
  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('fsharp', [
  7. // comments - single line
  8. [
  9. {
  10. line: '// one line comment',
  11. tokens: [{ startIndex: 0, type: 'comment.fs' }]
  12. }
  13. ],
  14. [
  15. {
  16. line: '//',
  17. tokens: [{ startIndex: 0, type: 'comment.fs' }]
  18. }
  19. ],
  20. [
  21. {
  22. line: ' // a comment',
  23. tokens: [
  24. { startIndex: 0, type: '' },
  25. { startIndex: 4, type: 'comment.fs' }
  26. ]
  27. }
  28. ],
  29. [
  30. {
  31. line: '// a comment',
  32. tokens: [{ startIndex: 0, type: 'comment.fs' }]
  33. }
  34. ],
  35. [
  36. {
  37. line: '//sticky comment',
  38. tokens: [{ startIndex: 0, type: 'comment.fs' }]
  39. }
  40. ],
  41. [
  42. {
  43. line: '/almost a comment',
  44. tokens: [
  45. { startIndex: 0, type: 'delimiter.fs' },
  46. { startIndex: 1, type: 'identifier.fs' },
  47. { startIndex: 7, type: '' },
  48. { startIndex: 8, type: 'identifier.fs' },
  49. { startIndex: 9, type: '' },
  50. { startIndex: 10, type: 'identifier.fs' }
  51. ]
  52. }
  53. ],
  54. [
  55. {
  56. line: '(/*almost a comment',
  57. tokens: [
  58. { startIndex: 0, type: 'delimiter.parenthesis.fs' },
  59. { startIndex: 1, type: 'delimiter.fs' },
  60. { startIndex: 3, type: 'identifier.fs' },
  61. { startIndex: 9, type: '' },
  62. { startIndex: 10, type: 'identifier.fs' },
  63. { startIndex: 11, type: '' },
  64. { startIndex: 12, type: 'identifier.fs' }
  65. ]
  66. }
  67. ],
  68. [
  69. {
  70. line: '1 / 2; (* comment',
  71. tokens: [
  72. { startIndex: 0, type: 'number.fs' },
  73. { startIndex: 1, type: '' },
  74. { startIndex: 2, type: 'delimiter.fs' },
  75. { startIndex: 3, type: '' },
  76. { startIndex: 4, type: 'number.fs' },
  77. { startIndex: 5, type: 'delimiter.fs' },
  78. { startIndex: 6, type: '' },
  79. { startIndex: 7, type: 'comment.fs' }
  80. ]
  81. }
  82. ],
  83. [
  84. {
  85. line: 'let x = 1; // my comment // is a nice one',
  86. tokens: [
  87. { startIndex: 0, type: 'keyword.let.fs' },
  88. { startIndex: 3, type: '' },
  89. { startIndex: 4, type: 'identifier.fs' },
  90. { startIndex: 5, type: '' },
  91. { startIndex: 6, type: 'delimiter.fs' },
  92. { startIndex: 7, type: '' },
  93. { startIndex: 8, type: 'number.fs' },
  94. { startIndex: 9, type: 'delimiter.fs' },
  95. { startIndex: 10, type: '' },
  96. { startIndex: 11, type: 'comment.fs' }
  97. ]
  98. }
  99. ],
  100. // Keywords
  101. [
  102. {
  103. line: 'namespace Application1',
  104. tokens: [
  105. { startIndex: 0, type: 'keyword.namespace.fs' },
  106. { startIndex: 9, type: '' },
  107. { startIndex: 10, type: 'identifier.fs' }
  108. ]
  109. }
  110. ],
  111. [
  112. {
  113. line: 'type MyType',
  114. tokens: [
  115. { startIndex: 0, type: 'keyword.type.fs' },
  116. { startIndex: 4, type: '' },
  117. { startIndex: 5, type: 'identifier.fs' }
  118. ]
  119. }
  120. ],
  121. [
  122. {
  123. line: 'module App =',
  124. tokens: [
  125. { startIndex: 0, type: 'keyword.module.fs' },
  126. { startIndex: 6, type: '' },
  127. { startIndex: 7, type: 'identifier.fs' },
  128. { startIndex: 10, type: '' },
  129. { startIndex: 11, type: 'delimiter.fs' }
  130. ]
  131. }
  132. ],
  133. [
  134. {
  135. line: 'let AppName = "App1"',
  136. tokens: [
  137. { startIndex: 0, type: 'keyword.let.fs' },
  138. { startIndex: 3, type: '' },
  139. { startIndex: 4, type: 'identifier.fs' },
  140. { startIndex: 11, type: '' },
  141. { startIndex: 12, type: 'delimiter.fs' },
  142. { startIndex: 13, type: '' },
  143. { startIndex: 14, type: 'string.fs' }
  144. ]
  145. }
  146. ],
  147. // Comments - range comment
  148. [
  149. {
  150. line: '(* a simple comment *)',
  151. tokens: [{ startIndex: 0, type: 'comment.fs' }]
  152. }
  153. ],
  154. [
  155. {
  156. line: 'let x = (* a simple comment *) 1',
  157. tokens: [
  158. { startIndex: 0, type: 'keyword.let.fs' },
  159. { startIndex: 3, type: '' },
  160. { startIndex: 4, type: 'identifier.fs' },
  161. { startIndex: 5, type: '' },
  162. { startIndex: 6, type: 'delimiter.fs' },
  163. { startIndex: 7, type: '' },
  164. { startIndex: 8, type: 'comment.fs' },
  165. { startIndex: 30, type: '' },
  166. { startIndex: 31, type: 'number.fs' }
  167. ]
  168. }
  169. ],
  170. [
  171. {
  172. line: 'x = (**)',
  173. tokens: [
  174. { startIndex: 0, type: 'identifier.fs' },
  175. { startIndex: 1, type: '' },
  176. { startIndex: 2, type: 'delimiter.fs' },
  177. { startIndex: 3, type: '' },
  178. { startIndex: 4, type: 'comment.fs' }
  179. ]
  180. }
  181. ],
  182. [
  183. {
  184. line: 'x = (*)',
  185. tokens: [
  186. { startIndex: 0, type: 'identifier.fs' },
  187. { startIndex: 1, type: '' },
  188. { startIndex: 2, type: 'delimiter.fs' },
  189. { startIndex: 3, type: '' },
  190. { startIndex: 4, type: 'delimiter.parenthesis.fs' },
  191. { startIndex: 5, type: 'delimiter.fs' },
  192. { startIndex: 6, type: 'delimiter.parenthesis.fs' }
  193. ]
  194. }
  195. ],
  196. // Numbers
  197. [
  198. {
  199. line: '0',
  200. tokens: [{ startIndex: 0, type: 'number.fs' }]
  201. }
  202. ],
  203. [
  204. {
  205. line: '0x123',
  206. tokens: [{ startIndex: 0, type: 'number.hex.fs' }]
  207. }
  208. ],
  209. [
  210. {
  211. line: '23.5',
  212. tokens: [{ startIndex: 0, type: 'number.float.fs' }]
  213. }
  214. ],
  215. [
  216. {
  217. line: '23.5e3',
  218. tokens: [{ startIndex: 0, type: 'number.float.fs' }]
  219. }
  220. ],
  221. [
  222. {
  223. line: '23.5E3',
  224. tokens: [{ startIndex: 0, type: 'number.float.fs' }]
  225. }
  226. ],
  227. [
  228. {
  229. line: '23.5F',
  230. tokens: [{ startIndex: 0, type: 'number.float.fs' }]
  231. }
  232. ],
  233. [
  234. {
  235. line: '23.5f',
  236. tokens: [{ startIndex: 0, type: 'number.float.fs' }]
  237. }
  238. ],
  239. [
  240. {
  241. line: '1.72E3F',
  242. tokens: [{ startIndex: 0, type: 'number.float.fs' }]
  243. }
  244. ],
  245. [
  246. {
  247. line: '1.72E3f',
  248. tokens: [{ startIndex: 0, type: 'number.float.fs' }]
  249. }
  250. ],
  251. [
  252. {
  253. line: '1.72e3F',
  254. tokens: [{ startIndex: 0, type: 'number.float.fs' }]
  255. }
  256. ],
  257. [
  258. {
  259. line: '1.72e3f',
  260. tokens: [{ startIndex: 0, type: 'number.float.fs' }]
  261. }
  262. ],
  263. [
  264. {
  265. line: '23.5M',
  266. tokens: [{ startIndex: 0, type: 'number.float.fs' }]
  267. }
  268. ],
  269. [
  270. {
  271. line: '23.5m',
  272. tokens: [{ startIndex: 0, type: 'number.float.fs' }]
  273. }
  274. ],
  275. [
  276. {
  277. line: '1.72E3M',
  278. tokens: [{ startIndex: 0, type: 'number.float.fs' }]
  279. }
  280. ],
  281. [
  282. {
  283. line: '1.72E3m',
  284. tokens: [{ startIndex: 0, type: 'number.float.fs' }]
  285. }
  286. ],
  287. [
  288. {
  289. line: '1.72e3M',
  290. tokens: [{ startIndex: 0, type: 'number.float.fs' }]
  291. }
  292. ],
  293. [
  294. {
  295. line: '1.72e3m',
  296. tokens: [{ startIndex: 0, type: 'number.float.fs' }]
  297. }
  298. ],
  299. [
  300. {
  301. line: '0+0',
  302. tokens: [
  303. { startIndex: 0, type: 'number.fs' },
  304. { startIndex: 1, type: 'delimiter.fs' },
  305. { startIndex: 2, type: 'number.fs' }
  306. ]
  307. }
  308. ],
  309. [
  310. {
  311. line: '100+10',
  312. tokens: [
  313. { startIndex: 0, type: 'number.fs' },
  314. { startIndex: 3, type: 'delimiter.fs' },
  315. { startIndex: 4, type: 'number.fs' }
  316. ]
  317. }
  318. ],
  319. [
  320. {
  321. line: '0 + 0',
  322. tokens: [
  323. { startIndex: 0, type: 'number.fs' },
  324. { startIndex: 1, type: '' },
  325. { startIndex: 2, type: 'delimiter.fs' },
  326. { startIndex: 3, type: '' },
  327. { startIndex: 4, type: 'number.fs' }
  328. ]
  329. }
  330. ],
  331. [
  332. {
  333. line: '0b00000101',
  334. tokens: [{ startIndex: 0, type: 'number.bin.fs' }]
  335. }
  336. ],
  337. [
  338. {
  339. line: '86y',
  340. tokens: [{ startIndex: 0, type: 'number.fs' }]
  341. }
  342. ],
  343. [
  344. {
  345. line: '0b00000101y',
  346. tokens: [{ startIndex: 0, type: 'number.bin.fs' }]
  347. }
  348. ],
  349. [
  350. {
  351. line: '86s',
  352. tokens: [{ startIndex: 0, type: 'number.fs' }]
  353. }
  354. ],
  355. [
  356. {
  357. line: '86us',
  358. tokens: [{ startIndex: 0, type: 'number.fs' }]
  359. }
  360. ],
  361. [
  362. {
  363. line: '86',
  364. tokens: [{ startIndex: 0, type: 'number.fs' }]
  365. }
  366. ],
  367. [
  368. {
  369. line: '86l',
  370. tokens: [{ startIndex: 0, type: 'number.fs' }]
  371. }
  372. ],
  373. [
  374. {
  375. line: '86u',
  376. tokens: [{ startIndex: 0, type: 'number.fs' }]
  377. }
  378. ],
  379. [
  380. {
  381. line: '86ul',
  382. tokens: [{ startIndex: 0, type: 'number.fs' }]
  383. }
  384. ],
  385. [
  386. {
  387. line: '0x00002D3Fn',
  388. tokens: [{ startIndex: 0, type: 'number.hex.fs' }]
  389. }
  390. ],
  391. [
  392. {
  393. line: '0x00002D3Fun',
  394. tokens: [{ startIndex: 0, type: 'number.hex.fs' }]
  395. }
  396. ],
  397. [
  398. {
  399. line: '86L',
  400. tokens: [{ startIndex: 0, type: 'number.fs' }]
  401. }
  402. ],
  403. [
  404. {
  405. line: '86UL',
  406. tokens: [{ startIndex: 0, type: 'number.fs' }]
  407. }
  408. ],
  409. [
  410. {
  411. line: '9999999999999999999999999999I',
  412. tokens: [{ startIndex: 0, type: 'number.fs' }]
  413. }
  414. ],
  415. [
  416. {
  417. line: '0x00002D3FLF',
  418. tokens: [{ startIndex: 0, type: 'number.float.fs' }]
  419. }
  420. ],
  421. [
  422. {
  423. line: '(* This operator -> (*) should be ignored *) let i = 0',
  424. tokens: [
  425. { startIndex: 0, type: 'comment.fs' },
  426. { startIndex: 44, type: '' },
  427. { startIndex: 45, type: 'keyword.let.fs' },
  428. { startIndex: 48, type: '' },
  429. { startIndex: 49, type: 'identifier.fs' },
  430. { startIndex: 50, type: '' },
  431. { startIndex: 51, type: 'delimiter.fs' },
  432. { startIndex: 52, type: '' },
  433. { startIndex: 53, type: 'number.fs' }
  434. ]
  435. }
  436. ]
  437. ]);