fsharp.test.ts 7.3 KB

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