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.

spec-parser.spec.ts 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import descriptionTokenizer from '../../src/parser/tokenizers/description';
  2. import nameTokenizer from '../../src/parser/tokenizers/name';
  3. import tagTokenizer from '../../src/parser/tokenizers/tag';
  4. import typeTokenizer from '../../src/parser/tokenizers/type';
  5. import getParser from '../../src/parser/spec-parser';
  6. import { seedTokens, seedSpec } from '../../src/util';
  7. import { Spec, Problem } from '../../src/primitives';
  8. const parse = getParser({
  9. tokenizers: [
  10. tagTokenizer(),
  11. typeTokenizer(),
  12. nameTokenizer(),
  13. descriptionTokenizer(),
  14. ],
  15. });
  16. const tokenizer = (message: string, critical = false) => {
  17. const problem: Problem = {
  18. code: 'custom',
  19. line: 1,
  20. message,
  21. critical,
  22. };
  23. return (spec: Spec) => ({
  24. ...spec,
  25. problems: [...spec.problems, problem],
  26. });
  27. };
  28. test('all tokens', () => {
  29. const parsed = parse([
  30. {
  31. number: 1,
  32. source: '...',
  33. tokens: seedTokens({
  34. description: '@param {type} [name=value] description',
  35. }),
  36. },
  37. ]);
  38. expect(parsed).toEqual(
  39. seedSpec({
  40. tag: 'param',
  41. type: 'type',
  42. name: 'name',
  43. default: 'value',
  44. optional: true,
  45. description: 'description',
  46. source: [
  47. {
  48. number: 1,
  49. source: '...',
  50. tokens: seedTokens({
  51. tag: '@param',
  52. postTag: ' ',
  53. type: '{type}',
  54. postType: ' ',
  55. name: '[name=value]',
  56. postName: ' ',
  57. description: 'description',
  58. }),
  59. },
  60. ],
  61. })
  62. );
  63. });
  64. test('quotes in description', () => {
  65. const parsed = parse([
  66. {
  67. number: 1,
  68. source: '...',
  69. tokens: seedTokens({
  70. description:
  71. '@param {type} [name=value] description with "quoted" word',
  72. }),
  73. },
  74. ]);
  75. expect(parsed).toEqual(
  76. seedSpec({
  77. tag: 'param',
  78. type: 'type',
  79. name: 'name',
  80. default: 'value',
  81. optional: true,
  82. description: 'description with "quoted" word',
  83. source: [
  84. {
  85. number: 1,
  86. source: '...',
  87. tokens: seedTokens({
  88. tag: '@param',
  89. postTag: ' ',
  90. type: '{type}',
  91. postType: ' ',
  92. name: '[name=value]',
  93. postName: ' ',
  94. description: 'description with "quoted" word',
  95. }),
  96. },
  97. ],
  98. })
  99. );
  100. });
  101. test('collect non-critical errors', () => {
  102. const parse = getParser({
  103. tokenizers: [tokenizer('warning 1'), tokenizer('warning 2')],
  104. });
  105. const parsed = parse([
  106. {
  107. number: 1,
  108. source: '...',
  109. tokens: seedTokens({ description: 'description' }),
  110. },
  111. ]);
  112. expect(parsed).toEqual({
  113. tag: '',
  114. name: '',
  115. optional: false,
  116. type: '',
  117. description: '',
  118. problems: [
  119. {
  120. code: 'custom',
  121. line: 1,
  122. message: 'warning 1',
  123. critical: false,
  124. },
  125. {
  126. code: 'custom',
  127. line: 1,
  128. message: 'warning 2',
  129. critical: false,
  130. },
  131. ],
  132. source: [
  133. {
  134. number: 1,
  135. source: '...',
  136. tokens: seedTokens({ description: 'description' }),
  137. },
  138. ],
  139. });
  140. });
  141. test('stop on critical error', () => {
  142. const parse = getParser({
  143. tokenizers: [tokenizer('error 1', true), tokenizer('warning 2')],
  144. });
  145. const parsed = parse([
  146. {
  147. number: 1,
  148. source: '...',
  149. tokens: seedTokens({ description: 'description' }),
  150. },
  151. ]);
  152. expect(parsed).toEqual({
  153. tag: '',
  154. name: '',
  155. optional: false,
  156. type: '',
  157. description: '',
  158. problems: [
  159. {
  160. code: 'custom',
  161. line: 1,
  162. message: 'error 1',
  163. critical: true,
  164. },
  165. ],
  166. source: [
  167. {
  168. number: 1,
  169. source: '...',
  170. tokens: seedTokens({ description: 'description' }),
  171. },
  172. ],
  173. });
  174. });