Software zum Installieren eines Smart-Mirror Frameworks , zum Nutzen von hochschulrelevanten Informationen, auf einem Raspberry-Pi.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

parse.spec.js 36KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849
  1. const { parse } = require('../../lib/index.cjs');
  2. test('description only', () => {
  3. const parsed = parse(`
  4. /**
  5. * Description
  6. */`);
  7. expect(parsed).toEqual([
  8. {
  9. description: 'Description',
  10. tags: [],
  11. source: [
  12. {
  13. number: 1,
  14. source: ' /**',
  15. tokens: {
  16. start: ' ',
  17. delimiter: '/**',
  18. postDelimiter: '',
  19. tag: '',
  20. postTag: '',
  21. name: '',
  22. postName: '',
  23. type: '',
  24. postType: '',
  25. description: '',
  26. end: '',
  27. lineEnd: '',
  28. },
  29. },
  30. {
  31. number: 2,
  32. source: ' * Description',
  33. tokens: {
  34. start: ' ',
  35. delimiter: '*',
  36. postDelimiter: ' ',
  37. tag: '',
  38. postTag: '',
  39. name: '',
  40. postName: '',
  41. type: '',
  42. postType: '',
  43. description: 'Description',
  44. end: '',
  45. lineEnd: '',
  46. },
  47. },
  48. {
  49. number: 3,
  50. source: ' */',
  51. tokens: {
  52. start: ' ',
  53. delimiter: '',
  54. postDelimiter: '',
  55. tag: '',
  56. postTag: '',
  57. name: '',
  58. postName: '',
  59. type: '',
  60. postType: '',
  61. description: '',
  62. end: '*/',
  63. lineEnd: '',
  64. },
  65. },
  66. ],
  67. problems: [],
  68. },
  69. ]);
  70. });
  71. test('description one-liner', () => {
  72. const parsed = parse(`
  73. /** Description */
  74. var a`);
  75. expect(parsed).toEqual([
  76. {
  77. description: 'Description',
  78. tags: [],
  79. source: [
  80. {
  81. number: 1,
  82. source: ' /** Description */',
  83. tokens: {
  84. start: ' ',
  85. delimiter: '/**',
  86. postDelimiter: ' ',
  87. tag: '',
  88. postTag: '',
  89. name: '',
  90. postName: '',
  91. type: '',
  92. postType: '',
  93. description: 'Description ',
  94. end: '*/',
  95. lineEnd: '',
  96. },
  97. },
  98. ],
  99. problems: [],
  100. },
  101. ]);
  102. });
  103. test('block closed on same line', () => {
  104. const parsed = parse(`
  105. /**
  106. * Description */`);
  107. expect(parsed).toEqual([
  108. {
  109. description: 'Description',
  110. tags: [],
  111. source: [
  112. {
  113. number: 1,
  114. source: ' /**',
  115. tokens: {
  116. start: ' ',
  117. delimiter: '/**',
  118. postDelimiter: '',
  119. tag: '',
  120. postTag: '',
  121. name: '',
  122. postName: '',
  123. type: '',
  124. postType: '',
  125. description: '',
  126. end: '',
  127. lineEnd: '',
  128. },
  129. },
  130. {
  131. number: 2,
  132. source: ' * Description */',
  133. tokens: {
  134. start: ' ',
  135. delimiter: '*',
  136. postDelimiter: ' ',
  137. tag: '',
  138. postTag: '',
  139. name: '',
  140. postName: '',
  141. type: '',
  142. postType: '',
  143. description: 'Description ',
  144. end: '*/',
  145. lineEnd: '',
  146. },
  147. },
  148. ],
  149. problems: [],
  150. },
  151. ]);
  152. });
  153. test('no mid stars', () => {
  154. const parsed = parse(`
  155. /**
  156. Description
  157. */`);
  158. expect(parsed).toEqual([
  159. {
  160. description: 'Description',
  161. tags: [],
  162. source: [
  163. {
  164. number: 1,
  165. source: ' /**',
  166. tokens: {
  167. start: ' ',
  168. delimiter: '/**',
  169. postDelimiter: '',
  170. tag: '',
  171. postTag: '',
  172. name: '',
  173. postName: '',
  174. type: '',
  175. postType: '',
  176. description: '',
  177. end: '',
  178. lineEnd: '',
  179. },
  180. },
  181. {
  182. number: 2,
  183. source: ' Description',
  184. tokens: {
  185. start: ' ',
  186. delimiter: '',
  187. postDelimiter: '',
  188. tag: '',
  189. postTag: '',
  190. name: '',
  191. postName: '',
  192. type: '',
  193. postType: '',
  194. description: 'Description',
  195. end: '',
  196. lineEnd: '',
  197. },
  198. },
  199. {
  200. number: 3,
  201. source: ' */',
  202. tokens: {
  203. start: ' ',
  204. delimiter: '',
  205. postDelimiter: '',
  206. tag: '',
  207. postTag: '',
  208. name: '',
  209. postName: '',
  210. type: '',
  211. postType: '',
  212. description: '',
  213. end: '*/',
  214. lineEnd: '',
  215. },
  216. },
  217. ],
  218. problems: [],
  219. },
  220. ]);
  221. });
  222. test('skip surrounding empty lines while preserving line numbers', () => {
  223. const parsed = parse(`
  224. /**
  225. *
  226. *
  227. * Description first line
  228. *
  229. * Description second line
  230. *
  231. */
  232. var a`);
  233. expect(parsed).toEqual([
  234. {
  235. description: 'Description first line Description second line',
  236. tags: [],
  237. source: [
  238. {
  239. number: 1,
  240. source: ' /**',
  241. tokens: {
  242. start: ' ',
  243. delimiter: '/**',
  244. postDelimiter: '',
  245. tag: '',
  246. postTag: '',
  247. name: '',
  248. postName: '',
  249. type: '',
  250. postType: '',
  251. description: '',
  252. end: '',
  253. lineEnd: '',
  254. },
  255. },
  256. {
  257. number: 2,
  258. source: ' *',
  259. tokens: {
  260. start: ' ',
  261. delimiter: '*',
  262. postDelimiter: '',
  263. tag: '',
  264. postTag: '',
  265. name: '',
  266. postName: '',
  267. type: '',
  268. postType: '',
  269. description: '',
  270. end: '',
  271. lineEnd: '',
  272. },
  273. },
  274. {
  275. number: 3,
  276. source: ' *',
  277. tokens: {
  278. start: ' ',
  279. delimiter: '*',
  280. postDelimiter: '',
  281. tag: '',
  282. postTag: '',
  283. name: '',
  284. postName: '',
  285. type: '',
  286. postType: '',
  287. description: '',
  288. end: '',
  289. lineEnd: '',
  290. },
  291. },
  292. {
  293. number: 4,
  294. source: ' * Description first line',
  295. tokens: {
  296. start: ' ',
  297. delimiter: '*',
  298. postDelimiter: ' ',
  299. tag: '',
  300. postTag: '',
  301. name: '',
  302. postName: '',
  303. type: '',
  304. postType: '',
  305. description: 'Description first line',
  306. end: '',
  307. lineEnd: '',
  308. },
  309. },
  310. {
  311. number: 5,
  312. source: ' *',
  313. tokens: {
  314. start: ' ',
  315. delimiter: '*',
  316. postDelimiter: '',
  317. tag: '',
  318. postTag: '',
  319. name: '',
  320. postName: '',
  321. type: '',
  322. postType: '',
  323. description: '',
  324. end: '',
  325. lineEnd: '',
  326. },
  327. },
  328. {
  329. number: 6,
  330. source: ' * Description second line',
  331. tokens: {
  332. start: ' ',
  333. delimiter: '*',
  334. postDelimiter: ' ',
  335. tag: '',
  336. postTag: '',
  337. name: '',
  338. postName: '',
  339. type: '',
  340. postType: '',
  341. description: 'Description second line',
  342. end: '',
  343. lineEnd: '',
  344. },
  345. },
  346. {
  347. number: 7,
  348. source: ' *',
  349. tokens: {
  350. start: ' ',
  351. delimiter: '*',
  352. postDelimiter: '',
  353. tag: '',
  354. postTag: '',
  355. name: '',
  356. postName: '',
  357. type: '',
  358. postType: '',
  359. description: '',
  360. end: '',
  361. lineEnd: '',
  362. },
  363. },
  364. {
  365. number: 8,
  366. source: ' */',
  367. tokens: {
  368. start: ' ',
  369. delimiter: '',
  370. postDelimiter: '',
  371. tag: '',
  372. postTag: '',
  373. name: '',
  374. postName: '',
  375. type: '',
  376. postType: '',
  377. description: '',
  378. end: '*/',
  379. lineEnd: '',
  380. },
  381. },
  382. ],
  383. problems: [],
  384. },
  385. ]);
  386. });
  387. test('description on the first line', () => {
  388. const parsed = parse(`
  389. /** Description first line
  390. *
  391. * Description second line
  392. */
  393. var a`);
  394. expect(parsed).toEqual([
  395. {
  396. description: 'Description first line Description second line',
  397. tags: [],
  398. source: [
  399. {
  400. number: 1,
  401. source: ' /** Description first line',
  402. tokens: {
  403. start: ' ',
  404. delimiter: '/**',
  405. postDelimiter: ' ',
  406. tag: '',
  407. postTag: '',
  408. name: '',
  409. postName: '',
  410. type: '',
  411. postType: '',
  412. description: 'Description first line',
  413. end: '',
  414. lineEnd: '',
  415. },
  416. },
  417. {
  418. number: 2,
  419. source: ' *',
  420. tokens: {
  421. start: ' ',
  422. delimiter: '*',
  423. postDelimiter: '',
  424. tag: '',
  425. postTag: '',
  426. name: '',
  427. postName: '',
  428. type: '',
  429. postType: '',
  430. description: '',
  431. end: '',
  432. lineEnd: '',
  433. },
  434. },
  435. {
  436. number: 3,
  437. source: ' * Description second line',
  438. tokens: {
  439. start: ' ',
  440. delimiter: '*',
  441. postDelimiter: ' ',
  442. tag: '',
  443. postTag: '',
  444. name: '',
  445. postName: '',
  446. type: '',
  447. postType: '',
  448. description: 'Description second line',
  449. end: '',
  450. lineEnd: '',
  451. },
  452. },
  453. {
  454. number: 4,
  455. source: ' */',
  456. tokens: {
  457. start: ' ',
  458. delimiter: '',
  459. postDelimiter: '',
  460. tag: '',
  461. postTag: '',
  462. name: '',
  463. postName: '',
  464. type: '',
  465. postType: '',
  466. description: '',
  467. end: '*/',
  468. lineEnd: '',
  469. },
  470. },
  471. ],
  472. problems: [],
  473. },
  474. ]);
  475. });
  476. test('skip empty blocks', () => {
  477. const parsed = parse(`
  478. /**
  479. *
  480. */
  481. var a`);
  482. expect(parsed).toHaveLength(0);
  483. });
  484. test('multiple blocks', () => {
  485. const parsed = parse(`
  486. /**
  487. * Description first line
  488. */
  489. var a
  490. /**
  491. * Description second line
  492. */
  493. var b`);
  494. expect(parsed).toHaveLength(2);
  495. expect(parsed).toEqual([
  496. {
  497. description: 'Description first line',
  498. tags: [],
  499. source: [
  500. {
  501. number: 1,
  502. source: ' /**',
  503. tokens: {
  504. start: ' ',
  505. delimiter: '/**',
  506. postDelimiter: '',
  507. tag: '',
  508. postTag: '',
  509. name: '',
  510. postName: '',
  511. type: '',
  512. postType: '',
  513. description: '',
  514. end: '',
  515. lineEnd: '',
  516. },
  517. },
  518. {
  519. number: 2,
  520. source: ' * Description first line',
  521. tokens: {
  522. start: ' ',
  523. delimiter: '*',
  524. postDelimiter: ' ',
  525. tag: '',
  526. postTag: '',
  527. name: '',
  528. postName: '',
  529. type: '',
  530. postType: '',
  531. description: 'Description first line',
  532. end: '',
  533. lineEnd: '',
  534. },
  535. },
  536. {
  537. number: 3,
  538. source: ' */',
  539. tokens: {
  540. start: ' ',
  541. delimiter: '',
  542. postDelimiter: '',
  543. tag: '',
  544. postTag: '',
  545. name: '',
  546. postName: '',
  547. type: '',
  548. postType: '',
  549. description: '',
  550. end: '*/',
  551. lineEnd: '',
  552. },
  553. },
  554. ],
  555. problems: [],
  556. },
  557. {
  558. description: 'Description second line',
  559. tags: [],
  560. source: [
  561. {
  562. number: 6,
  563. source: ' /**',
  564. tokens: {
  565. start: ' ',
  566. delimiter: '/**',
  567. postDelimiter: '',
  568. tag: '',
  569. postTag: '',
  570. name: '',
  571. postName: '',
  572. type: '',
  573. postType: '',
  574. description: '',
  575. end: '',
  576. lineEnd: '',
  577. },
  578. },
  579. {
  580. number: 7,
  581. source: ' * Description second line',
  582. tokens: {
  583. start: ' ',
  584. delimiter: '*',
  585. postDelimiter: ' ',
  586. tag: '',
  587. postTag: '',
  588. name: '',
  589. postName: '',
  590. type: '',
  591. postType: '',
  592. description: 'Description second line',
  593. end: '',
  594. lineEnd: '',
  595. },
  596. },
  597. {
  598. number: 8,
  599. source: ' */',
  600. tokens: {
  601. start: ' ',
  602. delimiter: '',
  603. postDelimiter: '',
  604. tag: '',
  605. postTag: '',
  606. name: '',
  607. postName: '',
  608. type: '',
  609. postType: '',
  610. description: '',
  611. end: '*/',
  612. lineEnd: '',
  613. },
  614. },
  615. ],
  616. problems: [],
  617. },
  618. ]);
  619. });
  620. test('skip `/* */` blocks', () => {
  621. const parsed = parse(`
  622. /*
  623. *
  624. */
  625. var a`);
  626. expect(parsed).toHaveLength(0);
  627. });
  628. test('skip `/*** */` blocks', () => {
  629. const parsed = parse(`
  630. /***
  631. *
  632. */
  633. var a`);
  634. expect(parsed).toHaveLength(0);
  635. });
  636. test('tag only one-liner', () => {
  637. const parsed = parse(`/** @my-tag */`);
  638. const source = [
  639. {
  640. number: 0,
  641. source: '/** @my-tag */',
  642. tokens: {
  643. start: '',
  644. delimiter: '/**',
  645. postDelimiter: ' ',
  646. tag: '@my-tag',
  647. postTag: ' ',
  648. name: '',
  649. postName: '',
  650. type: '',
  651. postType: '',
  652. description: '',
  653. end: '*/',
  654. lineEnd: '',
  655. },
  656. },
  657. ];
  658. expect(parsed).toEqual([
  659. {
  660. description: '',
  661. tags: [
  662. {
  663. tag: 'my-tag',
  664. name: '',
  665. type: '',
  666. optional: false,
  667. description: '',
  668. problems: [],
  669. source,
  670. },
  671. ],
  672. source,
  673. problems: [],
  674. },
  675. ]);
  676. });
  677. test('tag only', () => {
  678. const parsed = parse(`
  679. /**
  680. *
  681. * @my-tag
  682. */
  683. var a`);
  684. const source = [
  685. {
  686. number: 1,
  687. source: ' /**',
  688. tokens: {
  689. start: ' ',
  690. delimiter: '/**',
  691. postDelimiter: '',
  692. tag: '',
  693. postTag: '',
  694. name: '',
  695. postName: '',
  696. type: '',
  697. postType: '',
  698. description: '',
  699. end: '',
  700. lineEnd: '',
  701. },
  702. },
  703. {
  704. number: 2,
  705. source: ' *',
  706. tokens: {
  707. start: ' ',
  708. delimiter: '*',
  709. postDelimiter: '',
  710. tag: '',
  711. postTag: '',
  712. name: '',
  713. postName: '',
  714. type: '',
  715. postType: '',
  716. description: '',
  717. end: '',
  718. lineEnd: '',
  719. },
  720. },
  721. {
  722. number: 3,
  723. source: ' * @my-tag',
  724. tokens: {
  725. start: ' ',
  726. delimiter: '*',
  727. postDelimiter: ' ',
  728. tag: '@my-tag',
  729. postTag: '',
  730. name: '',
  731. postName: '',
  732. type: '',
  733. postType: '',
  734. description: '',
  735. end: '',
  736. lineEnd: '',
  737. },
  738. },
  739. {
  740. number: 4,
  741. source: ' */',
  742. tokens: {
  743. start: ' ',
  744. delimiter: '',
  745. postDelimiter: '',
  746. tag: '',
  747. postTag: '',
  748. name: '',
  749. postName: '',
  750. type: '',
  751. postType: '',
  752. description: '',
  753. end: '*/',
  754. lineEnd: '',
  755. },
  756. },
  757. ];
  758. expect(parsed).toEqual([
  759. {
  760. description: '',
  761. tags: [
  762. {
  763. tag: 'my-tag',
  764. name: '',
  765. type: '',
  766. optional: false,
  767. description: '',
  768. problems: [],
  769. source: source.slice(2),
  770. },
  771. ],
  772. source,
  773. problems: [],
  774. },
  775. ]);
  776. });
  777. test('tag and type only', () => {
  778. const parsed = parse(`
  779. /**
  780. *
  781. * @my-tag {my.type}
  782. */
  783. var a`);
  784. const source = [
  785. {
  786. number: 1,
  787. source: ' /**',
  788. tokens: {
  789. start: ' ',
  790. delimiter: '/**',
  791. postDelimiter: '',
  792. tag: '',
  793. postTag: '',
  794. name: '',
  795. postName: '',
  796. type: '',
  797. postType: '',
  798. description: '',
  799. end: '',
  800. lineEnd: '',
  801. },
  802. },
  803. {
  804. number: 2,
  805. source: ' *',
  806. tokens: {
  807. start: ' ',
  808. delimiter: '*',
  809. postDelimiter: '',
  810. tag: '',
  811. postTag: '',
  812. name: '',
  813. postName: '',
  814. type: '',
  815. postType: '',
  816. description: '',
  817. end: '',
  818. lineEnd: '',
  819. },
  820. },
  821. {
  822. number: 3,
  823. source: ' * @my-tag {my.type}',
  824. tokens: {
  825. start: ' ',
  826. delimiter: '*',
  827. postDelimiter: ' ',
  828. tag: '@my-tag',
  829. postTag: ' ',
  830. name: '',
  831. postName: '',
  832. type: '{my.type}',
  833. postType: '',
  834. description: '',
  835. end: '',
  836. lineEnd: '',
  837. },
  838. },
  839. {
  840. number: 4,
  841. source: ' */',
  842. tokens: {
  843. start: ' ',
  844. delimiter: '',
  845. postDelimiter: '',
  846. tag: '',
  847. postTag: '',
  848. name: '',
  849. postName: '',
  850. type: '',
  851. postType: '',
  852. description: '',
  853. end: '*/',
  854. lineEnd: '',
  855. },
  856. },
  857. ];
  858. expect(parsed).toEqual([
  859. {
  860. description: '',
  861. tags: [
  862. {
  863. tag: 'my-tag',
  864. name: '',
  865. type: 'my.type',
  866. optional: false,
  867. description: '',
  868. problems: [],
  869. source: source.slice(2),
  870. },
  871. ],
  872. source,
  873. problems: [],
  874. },
  875. ]);
  876. });
  877. test('tag and name only', () => {
  878. const parsed = parse(`
  879. /**
  880. *
  881. * @my-tag my-name
  882. */
  883. var a`);
  884. const source = [
  885. {
  886. number: 1,
  887. source: ' /**',
  888. tokens: {
  889. start: ' ',
  890. delimiter: '/**',
  891. postDelimiter: '',
  892. tag: '',
  893. postTag: '',
  894. name: '',
  895. postName: '',
  896. type: '',
  897. postType: '',
  898. description: '',
  899. end: '',
  900. lineEnd: '',
  901. },
  902. },
  903. {
  904. number: 2,
  905. source: ' *',
  906. tokens: {
  907. start: ' ',
  908. delimiter: '*',
  909. postDelimiter: '',
  910. tag: '',
  911. postTag: '',
  912. name: '',
  913. postName: '',
  914. type: '',
  915. postType: '',
  916. description: '',
  917. end: '',
  918. lineEnd: '',
  919. },
  920. },
  921. {
  922. number: 3,
  923. source: ' * @my-tag my-name',
  924. tokens: {
  925. start: ' ',
  926. delimiter: '*',
  927. postDelimiter: ' ',
  928. tag: '@my-tag',
  929. postTag: ' ',
  930. name: 'my-name',
  931. postName: '',
  932. type: '',
  933. postType: '',
  934. description: '',
  935. end: '',
  936. lineEnd: '',
  937. },
  938. },
  939. {
  940. number: 4,
  941. source: ' */',
  942. tokens: {
  943. start: ' ',
  944. delimiter: '',
  945. postDelimiter: '',
  946. tag: '',
  947. postTag: '',
  948. name: '',
  949. postName: '',
  950. type: '',
  951. postType: '',
  952. description: '',
  953. end: '*/',
  954. lineEnd: '',
  955. },
  956. },
  957. ];
  958. expect(parsed).toEqual([
  959. {
  960. description: '',
  961. tags: [
  962. {
  963. tag: 'my-tag',
  964. name: 'my-name',
  965. type: '',
  966. optional: false,
  967. description: '',
  968. problems: [],
  969. source: source.slice(2),
  970. },
  971. ],
  972. source,
  973. problems: [],
  974. },
  975. ]);
  976. });
  977. test('tag, type, and name', () => {
  978. const parsed = parse(`
  979. /**
  980. *
  981. * @my-tag {my.type} my-name
  982. */
  983. var a`);
  984. const source = [
  985. {
  986. number: 1,
  987. source: ' /**',
  988. tokens: {
  989. start: ' ',
  990. delimiter: '/**',
  991. postDelimiter: '',
  992. tag: '',
  993. postTag: '',
  994. name: '',
  995. postName: '',
  996. type: '',
  997. postType: '',
  998. description: '',
  999. end: '',
  1000. lineEnd: '',
  1001. },
  1002. },
  1003. {
  1004. number: 2,
  1005. source: ' *',
  1006. tokens: {
  1007. start: ' ',
  1008. delimiter: '*',
  1009. postDelimiter: '',
  1010. tag: '',
  1011. postTag: '',
  1012. name: '',
  1013. postName: '',
  1014. type: '',
  1015. postType: '',
  1016. description: '',
  1017. end: '',
  1018. lineEnd: '',
  1019. },
  1020. },
  1021. {
  1022. number: 3,
  1023. source: ' * @my-tag {my.type} my-name',
  1024. tokens: {
  1025. start: ' ',
  1026. delimiter: '*',
  1027. postDelimiter: ' ',
  1028. tag: '@my-tag',
  1029. postTag: ' ',
  1030. name: 'my-name',
  1031. postName: '',
  1032. type: '{my.type}',
  1033. postType: ' ',
  1034. description: '',
  1035. end: '',
  1036. lineEnd: '',
  1037. },
  1038. },
  1039. {
  1040. number: 4,
  1041. source: ' */',
  1042. tokens: {
  1043. start: ' ',
  1044. delimiter: '',
  1045. postDelimiter: '',
  1046. tag: '',
  1047. postTag: '',
  1048. name: '',
  1049. postName: '',
  1050. type: '',
  1051. postType: '',
  1052. description: '',
  1053. end: '*/',
  1054. lineEnd: '',
  1055. },
  1056. },
  1057. ];
  1058. expect(parsed).toEqual([
  1059. {
  1060. description: '',
  1061. tags: [
  1062. {
  1063. tag: 'my-tag',
  1064. name: 'my-name',
  1065. type: 'my.type',
  1066. optional: false,
  1067. description: '',
  1068. problems: [],
  1069. source: source.slice(2),
  1070. },
  1071. ],
  1072. source,
  1073. problems: [],
  1074. },
  1075. ]);
  1076. });
  1077. test('tag, type, name, and description', () => {
  1078. const parsed = parse(`
  1079. /**
  1080. *
  1081. * @my-tag {my.type} my-name description text
  1082. */
  1083. var a`);
  1084. const source = [
  1085. {
  1086. number: 1,
  1087. source: ' /**',
  1088. tokens: {
  1089. start: ' ',
  1090. delimiter: '/**',
  1091. postDelimiter: '',
  1092. tag: '',
  1093. postTag: '',
  1094. name: '',
  1095. postName: '',
  1096. type: '',
  1097. postType: '',
  1098. description: '',
  1099. end: '',
  1100. lineEnd: '',
  1101. },
  1102. },
  1103. {
  1104. number: 2,
  1105. source: ' *',
  1106. tokens: {
  1107. start: ' ',
  1108. delimiter: '*',
  1109. postDelimiter: '',
  1110. tag: '',
  1111. postTag: '',
  1112. name: '',
  1113. postName: '',
  1114. type: '',
  1115. postType: '',
  1116. description: '',
  1117. end: '',
  1118. lineEnd: '',
  1119. },
  1120. },
  1121. {
  1122. number: 3,
  1123. source: ' * @my-tag {my.type} my-name description text',
  1124. tokens: {
  1125. start: ' ',
  1126. delimiter: '*',
  1127. postDelimiter: ' ',
  1128. tag: '@my-tag',
  1129. postTag: ' ',
  1130. name: 'my-name',
  1131. postName: ' ',
  1132. type: '{my.type}',
  1133. postType: ' ',
  1134. description: 'description text',
  1135. end: '',
  1136. lineEnd: '',
  1137. },
  1138. },
  1139. {
  1140. number: 4,
  1141. source: ' */',
  1142. tokens: {
  1143. start: ' ',
  1144. delimiter: '',
  1145. postDelimiter: '',
  1146. tag: '',
  1147. postTag: '',
  1148. name: '',
  1149. postName: '',
  1150. type: '',
  1151. postType: '',
  1152. description: '',
  1153. end: '*/',
  1154. lineEnd: '',
  1155. },
  1156. },
  1157. ];
  1158. expect(parsed).toEqual([
  1159. {
  1160. description: '',
  1161. tags: [
  1162. {
  1163. tag: 'my-tag',
  1164. name: 'my-name',
  1165. type: 'my.type',
  1166. optional: false,
  1167. description: 'description text',
  1168. problems: [],
  1169. source: source.slice(2),
  1170. },
  1171. ],
  1172. source,
  1173. problems: [],
  1174. },
  1175. ]);
  1176. });
  1177. test('description contains /**', () => {
  1178. const parsed = parse(`
  1179. /**
  1180. *
  1181. * @my-tag {my.type} my-name description text /**
  1182. */
  1183. var a`);
  1184. const source = [
  1185. {
  1186. number: 1,
  1187. source: ' /**',
  1188. tokens: {
  1189. start: ' ',
  1190. delimiter: '/**',
  1191. postDelimiter: '',
  1192. tag: '',
  1193. postTag: '',
  1194. name: '',
  1195. postName: '',
  1196. type: '',
  1197. postType: '',
  1198. description: '',
  1199. end: '',
  1200. lineEnd: '',
  1201. },
  1202. },
  1203. {
  1204. number: 2,
  1205. source: ' *',
  1206. tokens: {
  1207. start: ' ',
  1208. delimiter: '*',
  1209. postDelimiter: '',
  1210. tag: '',
  1211. postTag: '',
  1212. name: '',
  1213. postName: '',
  1214. type: '',
  1215. postType: '',
  1216. description: '',
  1217. end: '',
  1218. lineEnd: '',
  1219. },
  1220. },
  1221. {
  1222. number: 3,
  1223. source: ' * @my-tag {my.type} my-name description text /**',
  1224. tokens: {
  1225. start: ' ',
  1226. delimiter: '*',
  1227. postDelimiter: ' ',
  1228. tag: '@my-tag',
  1229. postTag: ' ',
  1230. name: 'my-name',
  1231. postName: ' ',
  1232. type: '{my.type}',
  1233. postType: ' ',
  1234. description: 'description text /**',
  1235. end: '',
  1236. lineEnd: '',
  1237. },
  1238. },
  1239. {
  1240. number: 4,
  1241. source: ' */',
  1242. tokens: {
  1243. start: ' ',
  1244. delimiter: '',
  1245. postDelimiter: '',
  1246. tag: '',
  1247. postTag: '',
  1248. name: '',
  1249. postName: '',
  1250. type: '',
  1251. postType: '',
  1252. description: '',
  1253. end: '*/',
  1254. lineEnd: '',
  1255. },
  1256. },
  1257. ];
  1258. expect(parsed).toEqual([
  1259. {
  1260. description: '',
  1261. tags: [
  1262. {
  1263. tag: 'my-tag',
  1264. name: 'my-name',
  1265. type: 'my.type',
  1266. optional: false,
  1267. description: 'description text /**',
  1268. problems: [],
  1269. source: source.slice(2),
  1270. },
  1271. ],
  1272. source,
  1273. problems: [],
  1274. },
  1275. ]);
  1276. });
  1277. test('tag, type, name, and description separated by mixed spaces', () => {
  1278. const parsed = parse(`
  1279. /**
  1280. *
  1281. * @my-tag\t {my.type}\t my-name\t description text
  1282. */
  1283. var a`);
  1284. const source = [
  1285. {
  1286. number: 1,
  1287. source: ' /**',
  1288. tokens: {
  1289. start: ' ',
  1290. delimiter: '/**',
  1291. postDelimiter: '',
  1292. tag: '',
  1293. postTag: '',
  1294. name: '',
  1295. postName: '',
  1296. type: '',
  1297. postType: '',
  1298. description: '',
  1299. end: '',
  1300. lineEnd: '',
  1301. },
  1302. },
  1303. {
  1304. number: 2,
  1305. source: ' *',
  1306. tokens: {
  1307. start: ' ',
  1308. delimiter: '*',
  1309. postDelimiter: '',
  1310. tag: '',
  1311. postTag: '',
  1312. name: '',
  1313. postName: '',
  1314. type: '',
  1315. postType: '',
  1316. description: '',
  1317. end: '',
  1318. lineEnd: '',
  1319. },
  1320. },
  1321. {
  1322. number: 3,
  1323. source: ' * @my-tag\t {my.type}\t my-name\t description text',
  1324. tokens: {
  1325. start: ' ',
  1326. delimiter: '*',
  1327. postDelimiter: ' ',
  1328. tag: '@my-tag',
  1329. postTag: '\t ',
  1330. name: 'my-name',
  1331. postName: '\t ',
  1332. type: '{my.type}',
  1333. postType: '\t ',
  1334. description: 'description text',
  1335. end: '',
  1336. lineEnd: '',
  1337. },
  1338. },
  1339. {
  1340. number: 4,
  1341. source: ' */',
  1342. tokens: {
  1343. start: ' ',
  1344. delimiter: '',
  1345. postDelimiter: '',
  1346. tag: '',
  1347. postTag: '',
  1348. name: '',
  1349. postName: '',
  1350. type: '',
  1351. postType: '',
  1352. description: '',
  1353. end: '*/',
  1354. lineEnd: '',
  1355. },
  1356. },
  1357. ];
  1358. expect(parsed).toEqual([
  1359. {
  1360. description: '',
  1361. tags: [
  1362. {
  1363. tag: 'my-tag',
  1364. name: 'my-name',
  1365. type: 'my.type',
  1366. optional: false,
  1367. description: 'description text',
  1368. problems: [],
  1369. source: source.slice(2),
  1370. },
  1371. ],
  1372. source,
  1373. problems: [],
  1374. },
  1375. ]);
  1376. });
  1377. test('tag with multiline description', () => {
  1378. const parsed = parse(`
  1379. /**
  1380. * @my-tag {my.type} my-name description line 1
  1381. * description line 2
  1382. * description line 3
  1383. */
  1384. var a`);
  1385. const source = [
  1386. {
  1387. number: 1,
  1388. source: ' /**',
  1389. tokens: {
  1390. start: ' ',
  1391. delimiter: '/**',
  1392. postDelimiter: '',
  1393. tag: '',
  1394. postTag: '',
  1395. name: '',
  1396. postName: '',
  1397. type: '',
  1398. postType: '',
  1399. description: '',
  1400. end: '',
  1401. lineEnd: '',
  1402. },
  1403. },
  1404. {
  1405. number: 2,
  1406. source: ' * @my-tag {my.type} my-name description line 1',
  1407. tokens: {
  1408. start: ' ',
  1409. delimiter: '*',
  1410. postDelimiter: ' ',
  1411. tag: '@my-tag',
  1412. postTag: ' ',
  1413. name: 'my-name',
  1414. postName: ' ',
  1415. type: '{my.type}',
  1416. postType: ' ',
  1417. description: 'description line 1',
  1418. end: '',
  1419. lineEnd: '',
  1420. },
  1421. },
  1422. {
  1423. number: 3,
  1424. source: ' * description line 2',
  1425. tokens: {
  1426. start: ' ',
  1427. delimiter: '*',
  1428. postDelimiter: ' ',
  1429. tag: '',
  1430. postTag: '',
  1431. name: '',
  1432. postName: '',
  1433. type: '',
  1434. postType: '',
  1435. description: 'description line 2',
  1436. end: '',
  1437. lineEnd: '',
  1438. },
  1439. },
  1440. {
  1441. number: 4,
  1442. source: ' * description line 3',
  1443. tokens: {
  1444. start: ' ',
  1445. delimiter: '*',
  1446. postDelimiter: ' ',
  1447. tag: '',
  1448. postTag: '',
  1449. name: '',
  1450. postName: '',
  1451. type: '',
  1452. postType: '',
  1453. description: 'description line 3',
  1454. end: '',
  1455. lineEnd: '',
  1456. },
  1457. },
  1458. {
  1459. number: 5,
  1460. source: ' */',
  1461. tokens: {
  1462. start: ' ',
  1463. delimiter: '',
  1464. postDelimiter: '',
  1465. tag: '',
  1466. postTag: '',
  1467. name: '',
  1468. postName: '',
  1469. type: '',
  1470. postType: '',
  1471. description: '',
  1472. end: '*/',
  1473. lineEnd: '',
  1474. },
  1475. },
  1476. ];
  1477. expect(parsed).toEqual([
  1478. {
  1479. description: '',
  1480. tags: [
  1481. {
  1482. tag: 'my-tag',
  1483. name: 'my-name',
  1484. type: 'my.type',
  1485. optional: false,
  1486. description:
  1487. 'description line 1 description line 2 description line 3',
  1488. problems: [],
  1489. source: source.slice(1),
  1490. },
  1491. ],
  1492. source,
  1493. problems: [],
  1494. },
  1495. ]);
  1496. });
  1497. test('optional name', () => {
  1498. const parsed = parse(`
  1499. /**
  1500. *
  1501. * @my-tag {my.type} [my-name] description text
  1502. */
  1503. var a`);
  1504. const source = [
  1505. {
  1506. number: 1,
  1507. source: ' /**',
  1508. tokens: {
  1509. start: ' ',
  1510. delimiter: '/**',
  1511. postDelimiter: '',
  1512. tag: '',
  1513. postTag: '',
  1514. name: '',
  1515. postName: '',
  1516. type: '',
  1517. postType: '',
  1518. description: '',
  1519. end: '',
  1520. lineEnd: '',
  1521. },
  1522. },
  1523. {
  1524. number: 2,
  1525. source: ' *',
  1526. tokens: {
  1527. start: ' ',
  1528. delimiter: '*',
  1529. postDelimiter: '',
  1530. tag: '',
  1531. postTag: '',
  1532. name: '',
  1533. postName: '',
  1534. type: '',
  1535. postType: '',
  1536. description: '',
  1537. end: '',
  1538. lineEnd: '',
  1539. },
  1540. },
  1541. {
  1542. number: 3,
  1543. source: ' * @my-tag {my.type} [my-name] description text',
  1544. tokens: {
  1545. start: ' ',
  1546. delimiter: '*',
  1547. postDelimiter: ' ',
  1548. tag: '@my-tag',
  1549. postTag: ' ',
  1550. name: '[my-name]',
  1551. postName: ' ',
  1552. type: '{my.type}',
  1553. postType: ' ',
  1554. description: 'description text',
  1555. end: '',
  1556. lineEnd: '',
  1557. },
  1558. },
  1559. {
  1560. number: 4,
  1561. source: ' */',
  1562. tokens: {
  1563. start: ' ',
  1564. delimiter: '',
  1565. postDelimiter: '',
  1566. tag: '',
  1567. postTag: '',
  1568. name: '',
  1569. postName: '',
  1570. type: '',
  1571. postType: '',
  1572. description: '',
  1573. end: '*/',
  1574. lineEnd: '',
  1575. },
  1576. },
  1577. ];
  1578. expect(parsed).toEqual([
  1579. {
  1580. description: '',
  1581. tags: [
  1582. {
  1583. tag: 'my-tag',
  1584. name: 'my-name',
  1585. type: 'my.type',
  1586. optional: true,
  1587. description: 'description text',
  1588. problems: [],
  1589. source: source.slice(2),
  1590. },
  1591. ],
  1592. source,
  1593. problems: [],
  1594. },
  1595. ]);
  1596. });
  1597. test('report name errors', () => {
  1598. const parsed = parse(`
  1599. /**
  1600. *
  1601. * @my-tag {my.type} [my-name description text
  1602. */
  1603. var a`);
  1604. const source = [
  1605. {
  1606. number: 1,
  1607. source: ' /**',
  1608. tokens: {
  1609. start: ' ',
  1610. delimiter: '/**',
  1611. postDelimiter: '',
  1612. tag: '',
  1613. postTag: '',
  1614. name: '',
  1615. postName: '',
  1616. type: '',
  1617. postType: '',
  1618. description: '',
  1619. end: '',
  1620. lineEnd: '',
  1621. },
  1622. },
  1623. {
  1624. number: 2,
  1625. source: ' *',
  1626. tokens: {
  1627. start: ' ',
  1628. delimiter: '*',
  1629. postDelimiter: '',
  1630. tag: '',
  1631. postTag: '',
  1632. name: '',
  1633. postName: '',
  1634. type: '',
  1635. postType: '',
  1636. description: '',
  1637. end: '',
  1638. lineEnd: '',
  1639. },
  1640. },
  1641. {
  1642. number: 3,
  1643. source: ' * @my-tag {my.type} [my-name description text',
  1644. tokens: {
  1645. start: ' ',
  1646. delimiter: '*',
  1647. postDelimiter: ' ',
  1648. tag: '@my-tag',
  1649. postTag: ' ',
  1650. name: '',
  1651. postName: '',
  1652. type: '{my.type}',
  1653. postType: ' ',
  1654. description: '[my-name description text',
  1655. end: '',
  1656. lineEnd: '',
  1657. },
  1658. },
  1659. {
  1660. number: 4,
  1661. source: ' */',
  1662. tokens: {
  1663. start: ' ',
  1664. delimiter: '',
  1665. postDelimiter: '',
  1666. tag: '',
  1667. postTag: '',
  1668. name: '',
  1669. postName: '',
  1670. type: '',
  1671. postType: '',
  1672. description: '',
  1673. end: '*/',
  1674. lineEnd: '',
  1675. },
  1676. },
  1677. ];
  1678. const problems = [
  1679. {
  1680. code: 'spec:name:unpaired-brackets',
  1681. critical: true,
  1682. message: 'unpaired brackets',
  1683. line: 3,
  1684. },
  1685. ];
  1686. expect(parsed).toEqual([
  1687. {
  1688. description: '',
  1689. tags: [
  1690. {
  1691. tag: 'my-tag',
  1692. name: '',
  1693. type: 'my.type',
  1694. optional: false,
  1695. description: '',
  1696. source: source.slice(2),
  1697. problems,
  1698. },
  1699. ],
  1700. source,
  1701. problems,
  1702. },
  1703. ]);
  1704. });
  1705. test('misaligned block', () => {
  1706. const parsed = parse(`
  1707. /**
  1708. * @my-tag {my.type} my-name description line 1
  1709. description line 2
  1710. * description line 3
  1711. */
  1712. var a`);
  1713. const source = [
  1714. {
  1715. number: 1,
  1716. source: ' /**',
  1717. tokens: {
  1718. start: ' ',
  1719. delimiter: '/**',
  1720. postDelimiter: '',
  1721. tag: '',
  1722. postTag: '',
  1723. name: '',
  1724. postName: '',
  1725. type: '',
  1726. postType: '',
  1727. description: '',
  1728. end: '',
  1729. lineEnd: '',
  1730. },
  1731. },
  1732. {
  1733. number: 2,
  1734. source: '* @my-tag {my.type} my-name description line 1',
  1735. tokens: {
  1736. start: '',
  1737. delimiter: '*',
  1738. postDelimiter: ' ',
  1739. tag: '@my-tag',
  1740. postTag: ' ',
  1741. name: 'my-name',
  1742. postName: ' ',
  1743. type: '{my.type}',
  1744. postType: ' ',
  1745. description: 'description line 1',
  1746. end: '',
  1747. lineEnd: '',
  1748. },
  1749. },
  1750. {
  1751. number: 3,
  1752. source: ' description line 2',
  1753. tokens: {
  1754. start: ' ',
  1755. delimiter: '',
  1756. postDelimiter: '',
  1757. tag: '',
  1758. postTag: '',
  1759. name: '',
  1760. postName: '',
  1761. type: '',
  1762. postType: '',
  1763. description: 'description line 2',
  1764. end: '',
  1765. lineEnd: '',
  1766. },
  1767. },
  1768. {
  1769. number: 4,
  1770. source: ' * description line 3',
  1771. tokens: {
  1772. start: ' ',
  1773. delimiter: '*',
  1774. postDelimiter: ' ',
  1775. tag: '',
  1776. postTag: '',
  1777. name: '',
  1778. postName: '',
  1779. type: '',
  1780. postType: '',
  1781. description: 'description line 3',
  1782. end: '',
  1783. lineEnd: '',
  1784. },
  1785. },
  1786. {
  1787. number: 5,
  1788. source: ' */',
  1789. tokens: {
  1790. start: ' ',
  1791. delimiter: '',
  1792. postDelimiter: '',
  1793. tag: '',
  1794. postTag: '',
  1795. name: '',
  1796. postName: '',
  1797. type: '',
  1798. postType: '',
  1799. description: '',
  1800. end: '*/',
  1801. lineEnd: '',
  1802. },
  1803. },
  1804. ];
  1805. expect(parsed).toEqual([
  1806. {
  1807. description: '',
  1808. tags: [
  1809. {
  1810. tag: 'my-tag',
  1811. name: 'my-name',
  1812. type: 'my.type',
  1813. optional: false,
  1814. description:
  1815. 'description line 1 description line 2 description line 3',
  1816. problems: [],
  1817. source: source.slice(1),
  1818. },
  1819. ],
  1820. source,
  1821. problems: [],
  1822. },
  1823. ]);
  1824. });