clojure.test.ts 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  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 { ITestItem, testTokenization } from '../test/testRunner';
  6. const specialForms = [
  7. '.',
  8. 'catch',
  9. 'def',
  10. 'do',
  11. 'if',
  12. 'monitor-enter',
  13. 'monitor-exit',
  14. 'new',
  15. 'quote',
  16. 'recur',
  17. 'set!',
  18. 'throw',
  19. 'try',
  20. 'var'
  21. ];
  22. const coreSymbols = [
  23. '*',
  24. "*'",
  25. '*1',
  26. '*2',
  27. '*3',
  28. '*agent*',
  29. '*allow-unresolved-vars*',
  30. '*assert*',
  31. '*clojure-version*',
  32. '*command-line-args*',
  33. '*compile-files*',
  34. '*compile-path*',
  35. '*compiler-options*',
  36. '*data-readers*',
  37. '*default-data-reader-fn*',
  38. '*e',
  39. '*err*',
  40. '*file*',
  41. '*flush-on-newline*',
  42. '*fn-loader*',
  43. '*in*',
  44. '*math-context*',
  45. '*ns*',
  46. '*out*',
  47. '*print-dup*',
  48. '*print-length*',
  49. '*print-level*',
  50. '*print-meta*',
  51. '*print-namespace-maps*',
  52. '*print-readably*',
  53. '*read-eval*',
  54. '*reader-resolver*',
  55. '*source-path*',
  56. '*suppress-read*',
  57. '*unchecked-math*',
  58. '*use-context-classloader*',
  59. '*verbose-defrecords*',
  60. '*warn-on-reflection*',
  61. '+',
  62. "+'",
  63. '-',
  64. "-'",
  65. '->',
  66. '->>',
  67. '->ArrayChunk',
  68. '->Eduction',
  69. '->Vec',
  70. '->VecNode',
  71. '->VecSeq',
  72. '-cache-protocol-fn',
  73. '-reset-methods',
  74. '..',
  75. '/',
  76. '<',
  77. '<=',
  78. '=',
  79. '==',
  80. '>',
  81. '>=',
  82. 'EMPTY-NODE',
  83. 'Inst',
  84. 'StackTraceElement->vec',
  85. 'Throwable->map',
  86. 'accessor',
  87. 'aclone',
  88. 'add-classpath',
  89. 'add-watch',
  90. 'agent',
  91. 'agent-error',
  92. 'agent-errors',
  93. 'aget',
  94. 'alength',
  95. 'alias',
  96. 'all-ns',
  97. 'alter',
  98. 'alter-meta!',
  99. 'alter-var-root',
  100. 'amap',
  101. 'ancestors',
  102. 'and',
  103. 'any?',
  104. 'apply',
  105. 'areduce',
  106. 'array-map',
  107. 'as->',
  108. 'aset',
  109. 'aset-boolean',
  110. 'aset-byte',
  111. 'aset-char',
  112. 'aset-double',
  113. 'aset-float',
  114. 'aset-int',
  115. 'aset-long',
  116. 'aset-short',
  117. 'assert',
  118. 'assoc',
  119. 'assoc!',
  120. 'assoc-in',
  121. 'associative?',
  122. 'atom',
  123. 'await',
  124. 'await-for',
  125. 'await1',
  126. 'bases',
  127. 'bean',
  128. 'bigdec',
  129. 'bigint',
  130. 'biginteger',
  131. 'binding',
  132. 'bit-and',
  133. 'bit-and-not',
  134. 'bit-clear',
  135. 'bit-flip',
  136. 'bit-not',
  137. 'bit-or',
  138. 'bit-set',
  139. 'bit-shift-left',
  140. 'bit-shift-right',
  141. 'bit-test',
  142. 'bit-xor',
  143. 'boolean',
  144. 'boolean-array',
  145. 'boolean?',
  146. 'booleans',
  147. 'bound-fn',
  148. 'bound-fn*',
  149. 'bound?',
  150. 'bounded-count',
  151. 'butlast',
  152. 'byte',
  153. 'byte-array',
  154. 'bytes',
  155. 'bytes?',
  156. 'case',
  157. 'cast',
  158. 'cat',
  159. 'char',
  160. 'char-array',
  161. 'char-escape-string',
  162. 'char-name-string',
  163. 'char?',
  164. 'chars',
  165. 'chunk',
  166. 'chunk-append',
  167. 'chunk-buffer',
  168. 'chunk-cons',
  169. 'chunk-first',
  170. 'chunk-next',
  171. 'chunk-rest',
  172. 'chunked-seq?',
  173. 'class',
  174. 'class?',
  175. 'clear-agent-errors',
  176. 'clojure-version',
  177. 'coll?',
  178. 'comment',
  179. 'commute',
  180. 'comp',
  181. 'comparator',
  182. 'compare',
  183. 'compare-and-set!',
  184. 'compile',
  185. 'complement',
  186. 'completing',
  187. 'concat',
  188. 'cond',
  189. 'cond->',
  190. 'cond->>',
  191. 'condp',
  192. 'conj',
  193. 'conj!',
  194. 'cons',
  195. 'constantly',
  196. 'construct-proxy',
  197. 'contains?',
  198. 'count',
  199. 'counted?',
  200. 'create-ns',
  201. 'create-struct',
  202. 'cycle',
  203. 'dec',
  204. "dec'",
  205. 'decimal?',
  206. 'declare',
  207. 'dedupe',
  208. 'default-data-readers',
  209. 'definline',
  210. 'definterface',
  211. 'defmacro',
  212. 'defmethod',
  213. 'defmulti',
  214. 'defn',
  215. 'defn-',
  216. 'defonce',
  217. 'defprotocol',
  218. 'defrecord',
  219. 'defstruct',
  220. 'deftype',
  221. 'delay',
  222. 'delay?',
  223. 'deliver',
  224. 'denominator',
  225. 'deref',
  226. 'derive',
  227. 'descendants',
  228. 'destructure',
  229. 'disj',
  230. 'disj!',
  231. 'dissoc',
  232. 'dissoc!',
  233. 'distinct',
  234. 'distinct?',
  235. 'doall',
  236. 'dorun',
  237. 'doseq',
  238. 'dosync',
  239. 'dotimes',
  240. 'doto',
  241. 'double',
  242. 'double-array',
  243. 'double?',
  244. 'doubles',
  245. 'drop',
  246. 'drop-last',
  247. 'drop-while',
  248. 'eduction',
  249. 'empty',
  250. 'empty?',
  251. 'ensure',
  252. 'ensure-reduced',
  253. 'enumeration-seq',
  254. 'error-handler',
  255. 'error-mode',
  256. 'eval',
  257. 'even?',
  258. 'every-pred',
  259. 'every?',
  260. 'ex-data',
  261. 'ex-info',
  262. 'extend',
  263. 'extend-protocol',
  264. 'extend-type',
  265. 'extenders',
  266. 'extends?',
  267. 'false?',
  268. 'ffirst',
  269. 'file-seq',
  270. 'filter',
  271. 'filterv',
  272. 'find',
  273. 'find-keyword',
  274. 'find-ns',
  275. 'find-protocol-impl',
  276. 'find-protocol-method',
  277. 'find-var',
  278. 'first',
  279. 'flatten',
  280. 'float',
  281. 'float-array',
  282. 'float?',
  283. 'floats',
  284. 'flush',
  285. 'fn',
  286. 'fn?',
  287. 'fnext',
  288. 'fnil',
  289. 'for',
  290. 'force',
  291. 'format',
  292. 'frequencies',
  293. 'future',
  294. 'future-call',
  295. 'future-cancel',
  296. 'future-cancelled?',
  297. 'future-done?',
  298. 'future?',
  299. 'gen-class',
  300. 'gen-interface',
  301. 'gensym',
  302. 'get',
  303. 'get-in',
  304. 'get-method',
  305. 'get-proxy-class',
  306. 'get-thread-bindings',
  307. 'get-validator',
  308. 'group-by',
  309. 'halt-when',
  310. 'hash',
  311. 'hash-combine',
  312. 'hash-map',
  313. 'hash-ordered-coll',
  314. 'hash-set',
  315. 'hash-unordered-coll',
  316. 'ident?',
  317. 'identical?',
  318. 'identity',
  319. 'if-let',
  320. 'if-not',
  321. 'if-some',
  322. 'ifn?',
  323. 'import',
  324. 'in-ns',
  325. 'inc',
  326. "inc'",
  327. 'indexed?',
  328. 'init-proxy',
  329. 'inst-ms',
  330. 'inst-ms*',
  331. 'inst?',
  332. 'instance?',
  333. 'int',
  334. 'int-array',
  335. 'int?',
  336. 'integer?',
  337. 'interleave',
  338. 'intern',
  339. 'interpose',
  340. 'into',
  341. 'into-array',
  342. 'ints',
  343. 'io!',
  344. 'isa?',
  345. 'iterate',
  346. 'iterator-seq',
  347. 'juxt',
  348. 'keep',
  349. 'keep-indexed',
  350. 'key',
  351. 'keys',
  352. 'keyword',
  353. 'keyword?',
  354. 'last',
  355. 'lazy-cat',
  356. 'lazy-seq',
  357. 'let',
  358. 'letfn',
  359. 'line-seq',
  360. 'list',
  361. 'list*',
  362. 'list?',
  363. 'load',
  364. 'load-file',
  365. 'load-reader',
  366. 'load-string',
  367. 'loaded-libs',
  368. 'locking',
  369. 'long',
  370. 'long-array',
  371. 'longs',
  372. 'loop',
  373. 'macroexpand',
  374. 'macroexpand-1',
  375. 'make-array',
  376. 'make-hierarchy',
  377. 'map',
  378. 'map-entry?',
  379. 'map-indexed',
  380. 'map?',
  381. 'mapcat',
  382. 'mapv',
  383. 'max',
  384. 'max-key',
  385. 'memfn',
  386. 'memoize',
  387. 'merge',
  388. 'merge-with',
  389. 'meta',
  390. 'method-sig',
  391. 'methods',
  392. 'min',
  393. 'min-key',
  394. 'mix-collection-hash',
  395. 'mod',
  396. 'munge',
  397. 'name',
  398. 'namespace',
  399. 'namespace-munge',
  400. 'nat-int?',
  401. 'neg-int?',
  402. 'neg?',
  403. 'newline',
  404. 'next',
  405. 'nfirst',
  406. 'nil?',
  407. 'nnext',
  408. 'not',
  409. 'not-any?',
  410. 'not-empty',
  411. 'not-every?',
  412. 'not=',
  413. 'ns',
  414. 'ns-aliases',
  415. 'ns-imports',
  416. 'ns-interns',
  417. 'ns-map',
  418. 'ns-name',
  419. 'ns-publics',
  420. 'ns-refers',
  421. 'ns-resolve',
  422. 'ns-unalias',
  423. 'ns-unmap',
  424. 'nth',
  425. 'nthnext',
  426. 'nthrest',
  427. 'num',
  428. 'number?',
  429. 'numerator',
  430. 'object-array',
  431. 'odd?',
  432. 'or',
  433. 'parents',
  434. 'partial',
  435. 'partition',
  436. 'partition-all',
  437. 'partition-by',
  438. 'pcalls',
  439. 'peek',
  440. 'persistent!',
  441. 'pmap',
  442. 'pop',
  443. 'pop!',
  444. 'pop-thread-bindings',
  445. 'pos-int?',
  446. 'pos?',
  447. 'pr',
  448. 'pr-str',
  449. 'prefer-method',
  450. 'prefers',
  451. 'primitives-classnames',
  452. 'print',
  453. 'print-ctor',
  454. 'print-dup',
  455. 'print-method',
  456. 'print-simple',
  457. 'print-str',
  458. 'printf',
  459. 'println',
  460. 'println-str',
  461. 'prn',
  462. 'prn-str',
  463. 'promise',
  464. 'proxy',
  465. 'proxy-call-with-super',
  466. 'proxy-mappings',
  467. 'proxy-name',
  468. 'proxy-super',
  469. 'push-thread-bindings',
  470. 'pvalues',
  471. 'qualified-ident?',
  472. 'qualified-keyword?',
  473. 'qualified-symbol?',
  474. 'quot',
  475. 'rand',
  476. 'rand-int',
  477. 'rand-nth',
  478. 'random-sample',
  479. 'range',
  480. 'ratio?',
  481. 'rational?',
  482. 'rationalize',
  483. 're-find',
  484. 're-groups',
  485. 're-matcher',
  486. 're-matches',
  487. 're-pattern',
  488. 're-seq',
  489. 'read',
  490. 'read-line',
  491. 'read-string',
  492. 'reader-conditional',
  493. 'reader-conditional?',
  494. 'realized?',
  495. 'record?',
  496. 'reduce',
  497. 'reduce-kv',
  498. 'reduced',
  499. 'reduced?',
  500. 'reductions',
  501. 'ref',
  502. 'ref-history-count',
  503. 'ref-max-history',
  504. 'ref-min-history',
  505. 'ref-set',
  506. 'refer',
  507. 'refer-clojure',
  508. 'reify',
  509. 'release-pending-sends',
  510. 'rem',
  511. 'remove',
  512. 'remove-all-methods',
  513. 'remove-method',
  514. 'remove-ns',
  515. 'remove-watch',
  516. 'repeat',
  517. 'repeatedly',
  518. 'replace',
  519. 'replicate',
  520. 'require',
  521. 'reset!',
  522. 'reset-meta!',
  523. 'reset-vals!',
  524. 'resolve',
  525. 'rest',
  526. 'restart-agent',
  527. 'resultset-seq',
  528. 'reverse',
  529. 'reversible?',
  530. 'rseq',
  531. 'rsubseq',
  532. 'run!',
  533. 'satisfies?',
  534. 'second',
  535. 'select-keys',
  536. 'send',
  537. 'send-off',
  538. 'send-via',
  539. 'seq',
  540. 'seq?',
  541. 'seqable?',
  542. 'seque',
  543. 'sequence',
  544. 'sequential?',
  545. 'set',
  546. 'set-agent-send-executor!',
  547. 'set-agent-send-off-executor!',
  548. 'set-error-handler!',
  549. 'set-error-mode!',
  550. 'set-validator!',
  551. 'set?',
  552. 'short',
  553. 'short-array',
  554. 'shorts',
  555. 'shuffle',
  556. 'shutdown-agents',
  557. 'simple-ident?',
  558. 'simple-keyword?',
  559. 'simple-symbol?',
  560. 'slurp',
  561. 'some',
  562. 'some->',
  563. 'some->>',
  564. 'some-fn',
  565. 'some?',
  566. 'sort',
  567. 'sort-by',
  568. 'sorted-map',
  569. 'sorted-map-by',
  570. 'sorted-set',
  571. 'sorted-set-by',
  572. 'sorted?',
  573. 'special-symbol?',
  574. 'spit',
  575. 'split-at',
  576. 'split-with',
  577. 'str',
  578. 'string?',
  579. 'struct',
  580. 'struct-map',
  581. 'subs',
  582. 'subseq',
  583. 'subvec',
  584. 'supers',
  585. 'swap!',
  586. 'swap-vals!',
  587. 'symbol',
  588. 'symbol?',
  589. 'sync',
  590. 'tagged-literal',
  591. 'tagged-literal?',
  592. 'take',
  593. 'take-last',
  594. 'take-nth',
  595. 'take-while',
  596. 'test',
  597. 'the-ns',
  598. 'thread-bound?',
  599. 'time',
  600. 'to-array',
  601. 'to-array-2d',
  602. 'trampoline',
  603. 'transduce',
  604. 'transient',
  605. 'tree-seq',
  606. 'true?',
  607. 'type',
  608. 'unchecked-add',
  609. 'unchecked-add-int',
  610. 'unchecked-byte',
  611. 'unchecked-char',
  612. 'unchecked-dec',
  613. 'unchecked-dec-int',
  614. 'unchecked-divide-int',
  615. 'unchecked-double',
  616. 'unchecked-float',
  617. 'unchecked-inc',
  618. 'unchecked-inc-int',
  619. 'unchecked-int',
  620. 'unchecked-long',
  621. 'unchecked-multiply',
  622. 'unchecked-multiply-int',
  623. 'unchecked-negate',
  624. 'unchecked-negate-int',
  625. 'unchecked-remainder-int',
  626. 'unchecked-short',
  627. 'unchecked-subtract',
  628. 'unchecked-subtract-int',
  629. 'underive',
  630. 'unquote',
  631. 'unquote-splicing',
  632. 'unreduced',
  633. 'unsigned-bit-shift-right',
  634. 'update',
  635. 'update-in',
  636. 'update-proxy',
  637. 'uri?',
  638. 'use',
  639. 'uuid?',
  640. 'val',
  641. 'vals',
  642. 'var-get',
  643. 'var-set',
  644. 'var?',
  645. 'vary-meta',
  646. 'vec',
  647. 'vector',
  648. 'vector-of',
  649. 'vector?',
  650. 'volatile!',
  651. 'volatile?',
  652. 'vreset!',
  653. 'vswap!',
  654. 'when',
  655. 'when-first',
  656. 'when-let',
  657. 'when-not',
  658. 'when-some',
  659. 'while',
  660. 'with-bindings',
  661. 'with-bindings*',
  662. 'with-in-str',
  663. 'with-loading-context',
  664. 'with-local-vars',
  665. 'with-meta',
  666. 'with-open',
  667. 'with-out-str',
  668. 'with-precision',
  669. 'with-redefs',
  670. 'with-redefs-fn',
  671. 'xml-seq',
  672. 'zero?',
  673. 'zipmap'
  674. ];
  675. function createTestCases(specialForms: string[], type: string): ITestItem[] {
  676. const testCases = [];
  677. for (const specialForm of specialForms) {
  678. testCases.push({
  679. line: `${specialForm}`,
  680. tokens: [{ startIndex: 0, type: `${type}.clj` }]
  681. });
  682. }
  683. return testCases;
  684. }
  685. testTokenization('clojure', [
  686. // special forms
  687. createTestCases(specialForms, 'keyword'),
  688. // core symbols
  689. createTestCases(coreSymbols, 'keyword'),
  690. // atoms
  691. createTestCases(['false', 'nil', 'true'], 'constant'),
  692. // keywords
  693. createTestCases([':foo', '::bar', ':foo/bar', ':foo.bar/baz'], 'constant'),
  694. // numbers
  695. createTestCases(
  696. [
  697. '42',
  698. '+42',
  699. '-421',
  700. '42N',
  701. '+42N',
  702. '-42N',
  703. '0.42',
  704. '+0.42',
  705. '-0.42',
  706. '42M',
  707. '+42M',
  708. '-42M',
  709. '42.42M',
  710. '+42.42M',
  711. '-42.42M',
  712. '1/42',
  713. '+1/42',
  714. '-1/42',
  715. '0x42af',
  716. '+0x42af',
  717. '-0x42af',
  718. '0x42AF',
  719. '+0x42AF',
  720. '-0x42AF',
  721. '1e2',
  722. '1e+2',
  723. '1e-2',
  724. '+1e2',
  725. '+1e+2',
  726. '+1e-2',
  727. '-1e2',
  728. '-1e+2',
  729. '-1e-2',
  730. '-1.0e2',
  731. '-0.1e+2',
  732. '-1.01e-2',
  733. '1E2',
  734. '1E+2',
  735. '1E-2',
  736. '+1E2',
  737. '+1E+2',
  738. '+1E-2',
  739. '-1E2',
  740. '-1E+2',
  741. '-1E-2',
  742. '-1.0E2',
  743. '-0.1E+2',
  744. '-1.01E-2',
  745. '2r101010',
  746. '+2r101010',
  747. '-2r101010',
  748. '2r101010',
  749. '+2r101010',
  750. '-2r101010',
  751. '8r52',
  752. '+8r52',
  753. '-8r52',
  754. '36rhello',
  755. '+36rhello',
  756. '-36rhello',
  757. '36rz',
  758. '+36rz',
  759. '-36rz',
  760. '36rZ',
  761. '+36rZ',
  762. '-36rZ'
  763. ],
  764. 'number'
  765. ),
  766. // characters
  767. createTestCases(
  768. [
  769. '\\1',
  770. '\\a',
  771. '\\#',
  772. '\\\\',
  773. '\\"',
  774. '\\(',
  775. '\\A',
  776. '\\backspace',
  777. '\\formfeed',
  778. '\\newline',
  779. '\\space',
  780. '\\return',
  781. '\\tab',
  782. '\\o123',
  783. '\\u1000',
  784. '\\uAaAa',
  785. '\\u9F9F'
  786. ],
  787. 'string'
  788. ),
  789. // strings
  790. [
  791. {
  792. line: '"I\'m a little teapot."',
  793. tokens: [{ startIndex: 0, type: 'string.clj' }]
  794. },
  795. {
  796. line: '"I\'m a \\"little\\" teapot."',
  797. tokens: [
  798. { startIndex: 0, type: 'string.clj' },
  799. { startIndex: 7, type: 'string.escape.clj' },
  800. { startIndex: 9, type: 'string.clj' },
  801. { startIndex: 15, type: 'string.escape.clj' },
  802. { startIndex: 17, type: 'string.clj' }
  803. ]
  804. }
  805. ],
  806. // multi-line strings
  807. [
  808. {
  809. line: '"I\'m',
  810. tokens: [{ startIndex: 0, type: 'string.clj' }]
  811. },
  812. {
  813. line: '\\"a little\\"',
  814. tokens: [
  815. { startIndex: 0, type: 'string.escape.clj' },
  816. { startIndex: 2, type: 'string.clj' },
  817. { startIndex: 10, type: 'string.escape.clj' }
  818. ]
  819. },
  820. {
  821. line: 'teapot."',
  822. tokens: [{ startIndex: 0, type: 'string.clj' }]
  823. }
  824. ],
  825. // strings with other escapes in them (\" \' \\ \b \f \n \r \t)
  826. [
  827. {
  828. line: '"the escape \\" \\\' \\\\ \\b \\f \\n \\r \\t characters"',
  829. tokens: [
  830. { startIndex: 0, type: 'string.clj' },
  831. { startIndex: 12, type: 'string.escape.clj' },
  832. { startIndex: 14, type: 'string.clj' },
  833. { startIndex: 15, type: 'string.escape.clj' },
  834. { startIndex: 17, type: 'string.clj' },
  835. { startIndex: 18, type: 'string.escape.clj' },
  836. { startIndex: 20, type: 'string.clj' },
  837. { startIndex: 21, type: 'string.escape.clj' },
  838. { startIndex: 23, type: 'string.clj' },
  839. { startIndex: 24, type: 'string.escape.clj' },
  840. { startIndex: 26, type: 'string.clj' },
  841. { startIndex: 27, type: 'string.escape.clj' },
  842. { startIndex: 29, type: 'string.clj' },
  843. { startIndex: 30, type: 'string.escape.clj' },
  844. { startIndex: 32, type: 'string.clj' },
  845. { startIndex: 33, type: 'string.escape.clj' },
  846. { startIndex: 35, type: 'string.clj' }
  847. ]
  848. }
  849. ],
  850. // comments
  851. createTestCases(['; this is an in-line comment.', ';; this is a line comment.'], 'comment'),
  852. // `comment`
  853. [
  854. {
  855. line: '(comment)',
  856. tokens: [{ startIndex: 0, type: 'comment.clj' }]
  857. },
  858. {
  859. line: 'foo :bar 42',
  860. tokens: [
  861. { startIndex: 0, type: 'identifier.clj' },
  862. { startIndex: 3, type: 'white.clj' },
  863. { startIndex: 4, type: 'constant.clj' },
  864. { startIndex: 8, type: 'white.clj' },
  865. { startIndex: 9, type: 'number.clj' }
  866. ]
  867. },
  868. {
  869. line: '(comment (foo [bar :baz 1 "qux"]))',
  870. tokens: [{ startIndex: 0, type: 'comment.clj' }]
  871. },
  872. {
  873. line: '(comments foo bar)',
  874. tokens: [
  875. { startIndex: 0, type: 'delimiter.parenthesis.clj' },
  876. { startIndex: 1, type: 'identifier.clj' },
  877. { startIndex: 9, type: 'white.clj' },
  878. { startIndex: 10, type: 'identifier.clj' },
  879. { startIndex: 13, type: 'white.clj' },
  880. { startIndex: 14, type: 'identifier.clj' },
  881. { startIndex: 17, type: 'delimiter.parenthesis.clj' }
  882. ]
  883. },
  884. {
  885. line: '(comment6 foo bar)',
  886. tokens: [
  887. { startIndex: 0, type: 'delimiter.parenthesis.clj' },
  888. { startIndex: 1, type: 'identifier.clj' },
  889. { startIndex: 9, type: 'white.clj' },
  890. { startIndex: 10, type: 'identifier.clj' },
  891. { startIndex: 13, type: 'white.clj' },
  892. { startIndex: 14, type: 'identifier.clj' },
  893. { startIndex: 17, type: 'delimiter.parenthesis.clj' }
  894. ]
  895. },
  896. {
  897. line: '(comment foo',
  898. tokens: [{ startIndex: 0, type: 'comment.clj' }]
  899. },
  900. {
  901. line: 'foo',
  902. tokens: [{ startIndex: 0, type: 'comment.clj' }]
  903. }
  904. ],
  905. // reader macro characters
  906. createTestCases(['#', '@', '^', '`', '~', "'"], 'meta'),
  907. // treat comma as whitespace
  908. [
  909. {
  910. line: ', foo, :bar, "one", 2, ',
  911. tokens: [
  912. { startIndex: 0, type: 'white.clj' },
  913. { startIndex: 2, type: 'identifier.clj' },
  914. { startIndex: 5, type: 'white.clj' },
  915. { startIndex: 7, type: 'constant.clj' },
  916. { startIndex: 11, type: 'white.clj' },
  917. { startIndex: 13, type: 'string.clj' },
  918. { startIndex: 18, type: 'white.clj' },
  919. { startIndex: 20, type: 'number.clj' },
  920. { startIndex: 21, type: 'white.clj' }
  921. ]
  922. }
  923. ]
  924. ]);