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.

block-parser.spec.ts 3.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169
  1. import getParser from '../../src/parser/block-parser';
  2. import { Line } from '../../src/primitives';
  3. import { seedTokens } from '../../src/util';
  4. let source: Line[];
  5. beforeEach(() => {
  6. source = [
  7. {
  8. number: 1,
  9. source: ' /**',
  10. tokens: seedTokens({
  11. start: ' ',
  12. delimiter: '/**',
  13. postDelimiter: '',
  14. description: '',
  15. end: '',
  16. }),
  17. },
  18. {
  19. number: 2,
  20. source: ' * description 0',
  21. tokens: seedTokens({
  22. start: ' ',
  23. delimiter: '*',
  24. postDelimiter: ' ',
  25. description: 'description 0',
  26. end: '',
  27. }),
  28. },
  29. {
  30. number: 3,
  31. source: ' *',
  32. tokens: seedTokens({
  33. start: ' ',
  34. delimiter: '*',
  35. postDelimiter: '',
  36. description: '',
  37. end: '',
  38. }),
  39. },
  40. {
  41. number: 4,
  42. source: ' * description 1',
  43. tokens: seedTokens({
  44. start: ' ',
  45. delimiter: '*',
  46. postDelimiter: ' ',
  47. description: 'description 1',
  48. end: '',
  49. }),
  50. },
  51. {
  52. number: 5,
  53. source: ' *',
  54. tokens: seedTokens({
  55. start: ' ',
  56. delimiter: '*',
  57. postDelimiter: '',
  58. description: '',
  59. end: '',
  60. }),
  61. },
  62. {
  63. number: 6,
  64. source: ' * @param {string} value value description 0',
  65. tokens: seedTokens({
  66. start: ' ',
  67. delimiter: '*',
  68. postDelimiter: ' ',
  69. description: '@param {string} value value description 0',
  70. end: '',
  71. }),
  72. },
  73. {
  74. number: 7,
  75. source: ' ```',
  76. tokens: seedTokens({
  77. start: ' ',
  78. delimiter: '',
  79. postDelimiter: '',
  80. description: '```',
  81. end: '',
  82. }),
  83. },
  84. {
  85. number: 8,
  86. source: ' @sample code',
  87. tokens: seedTokens({
  88. start: ' ',
  89. delimiter: '',
  90. postDelimiter: '',
  91. description: '@sample code',
  92. end: '',
  93. }),
  94. },
  95. {
  96. number: 9,
  97. source: ' ```',
  98. tokens: seedTokens({
  99. start: ' ',
  100. delimiter: '',
  101. postDelimiter: '',
  102. description: '```',
  103. end: '',
  104. }),
  105. },
  106. {
  107. number: 10,
  108. source: ' * value description 1',
  109. tokens: seedTokens({
  110. start: ' ',
  111. delimiter: '*',
  112. postDelimiter: ' ',
  113. description: 'value description 1',
  114. end: '',
  115. }),
  116. },
  117. {
  118. number: 11,
  119. source: ' */',
  120. tokens: seedTokens({
  121. start: ' ',
  122. delimiter: '',
  123. postDelimiter: '',
  124. description: '',
  125. end: '*/',
  126. }),
  127. },
  128. ];
  129. });
  130. test('standard fences', () => {
  131. const parser = getParser();
  132. const groups: Line[][] = parser(source);
  133. expect(groups.length).toBe(2);
  134. expect(groups).toEqual([source.slice(0, 5), source.slice(5)]);
  135. });
  136. test('custom fence', () => {
  137. source = source.map((line) => {
  138. line.tokens.description = line.tokens.description.replace('```', '###');
  139. return line;
  140. });
  141. const parser = getParser({ fence: '###' });
  142. const groups: Line[][] = parser(source);
  143. expect(groups.length).toBe(2);
  144. expect(groups).toEqual([source.slice(0, 5), source.slice(5)]);
  145. });
  146. test('fence function', () => {
  147. source = source.map((line) => {
  148. line.tokens.description = line.tokens.description.replace('```', '###');
  149. return line;
  150. });
  151. function isFenced(source: string) {
  152. return source.split('###').length % 2 === 0;
  153. }
  154. const parser = getParser({ fence: isFenced });
  155. const groups: Line[][] = parser(source);
  156. expect(groups.length).toBe(2);
  157. expect(groups).toEqual([source.slice(0, 5), source.slice(5)]);
  158. });