fsharp.test.ts 7.8 KB

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