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.

parser.spec.ts 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. import getParser from '../../src/parser';
  2. import { seedTokens } from '../../src/util';
  3. test('block with tags', () => {
  4. const parsed = getParser()(`
  5. /**
  6. * Description may go
  7. * over few lines followed by @tags
  8. * @param {string} name name parameter
  9. *
  10. * @param {any} value value of any type
  11. */`);
  12. expect(parsed).toEqual([
  13. {
  14. description: 'Description may go over few lines followed by @tags',
  15. tags: [
  16. {
  17. tag: 'param',
  18. name: 'name',
  19. type: 'string',
  20. optional: false,
  21. description: 'name parameter',
  22. problems: [],
  23. source: [
  24. {
  25. number: 4,
  26. source: ' * @param {string} name name parameter',
  27. tokens: seedTokens({
  28. start: ' ',
  29. delimiter: '*',
  30. postDelimiter: ' ',
  31. tag: '@param',
  32. postTag: ' ',
  33. name: 'name',
  34. postName: ' ',
  35. type: '{string}',
  36. postType: ' ',
  37. description: 'name parameter',
  38. }),
  39. },
  40. {
  41. number: 5,
  42. source: ' *',
  43. tokens: seedTokens({
  44. start: ' ',
  45. delimiter: '*',
  46. }),
  47. },
  48. ],
  49. },
  50. {
  51. tag: 'param',
  52. name: 'value',
  53. type: 'any',
  54. optional: false,
  55. description: 'value of any type',
  56. problems: [],
  57. source: [
  58. {
  59. number: 6,
  60. source: ' * @param {any} value value of any type',
  61. tokens: seedTokens({
  62. start: ' ',
  63. delimiter: '*',
  64. postDelimiter: ' ',
  65. tag: '@param',
  66. postTag: ' ',
  67. name: 'value',
  68. postName: ' ',
  69. type: '{any}',
  70. postType: ' ',
  71. description: 'value of any type',
  72. }),
  73. },
  74. {
  75. number: 7,
  76. source: ' */',
  77. tokens: seedTokens({
  78. start: ' ',
  79. end: '*/',
  80. }),
  81. },
  82. ],
  83. },
  84. ],
  85. source: [
  86. {
  87. number: 1,
  88. source: ' /**',
  89. tokens: seedTokens({
  90. start: ' ',
  91. delimiter: '/**',
  92. }),
  93. },
  94. {
  95. number: 2,
  96. source: ' * Description may go ',
  97. tokens: seedTokens({
  98. start: ' ',
  99. delimiter: '*',
  100. postDelimiter: ' ',
  101. description: 'Description may go ',
  102. }),
  103. },
  104. {
  105. number: 3,
  106. source: ' * over few lines followed by @tags',
  107. tokens: seedTokens({
  108. start: ' ',
  109. delimiter: '*',
  110. postDelimiter: ' ',
  111. description: 'over few lines followed by @tags',
  112. }),
  113. },
  114. {
  115. number: 4,
  116. source: ' * @param {string} name name parameter',
  117. tokens: seedTokens({
  118. start: ' ',
  119. delimiter: '*',
  120. postDelimiter: ' ',
  121. tag: '@param',
  122. postTag: ' ',
  123. name: 'name',
  124. postName: ' ',
  125. type: '{string}',
  126. postType: ' ',
  127. description: 'name parameter',
  128. end: '',
  129. }),
  130. },
  131. {
  132. number: 5,
  133. source: ' *',
  134. tokens: seedTokens({
  135. start: ' ',
  136. delimiter: '*',
  137. }),
  138. },
  139. {
  140. number: 6,
  141. source: ' * @param {any} value value of any type',
  142. tokens: seedTokens({
  143. start: ' ',
  144. delimiter: '*',
  145. postDelimiter: ' ',
  146. tag: '@param',
  147. postTag: ' ',
  148. name: 'value',
  149. postName: ' ',
  150. type: '{any}',
  151. postType: ' ',
  152. description: 'value of any type',
  153. }),
  154. },
  155. {
  156. number: 7,
  157. source: ' */',
  158. tokens: seedTokens({
  159. start: ' ',
  160. end: '*/',
  161. }),
  162. },
  163. ],
  164. problems: [],
  165. },
  166. ]);
  167. });
  168. test('no source clonning', () => {
  169. const parsed = getParser()(`
  170. /**
  171. * Description may go
  172. * over few lines followed by @tags
  173. * @param {string} name name parameter
  174. *
  175. * @param {any} value value of any type
  176. */`);
  177. expect(parsed[0].tags[0].source[0] === parsed[0].source[3]).toBe(true);
  178. });
  179. test.each([
  180. ['empty', '/**\n*\n*/'],
  181. ['one-star', '/*\n*\n*/'],
  182. ['three-star', '/***\n*\n*/'],
  183. ['empty one-liner', '/** */'],
  184. ['one-star oneliner', '/* */'],
  185. ['three-star oneliner', '/*** */'],
  186. ])('skip block - %s', (name, source) => {
  187. expect(getParser()(source)).toEqual([]);
  188. });
  189. test.each([
  190. ['negative', -1],
  191. ['float', 1.5],
  192. ])('invalid start line - %s', (name, startLine) => {
  193. expect(() => getParser({ startLine })).toThrow('Invalid startLine');
  194. });