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-description-tokenizer.spec.ts 5.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227
  1. import descriptionTokenizer from '../../src/parser/tokenizers/description';
  2. import { seedSpec, seedTokens } from '../../src/util';
  3. const sourceSingle = [
  4. {
  5. number: 1,
  6. source: '...',
  7. tokens: seedTokens({ description: ' one two ' }),
  8. },
  9. ];
  10. const sourceMultiple = [
  11. {
  12. number: 1,
  13. source: '...',
  14. tokens: seedTokens({ description: 'one two ' }),
  15. },
  16. {
  17. number: 2,
  18. source: '...',
  19. tokens: seedTokens({ description: '' }),
  20. },
  21. {
  22. number: 3,
  23. source: '...',
  24. tokens: seedTokens({ description: ' three four' }),
  25. },
  26. {
  27. number: 4,
  28. source: '...',
  29. tokens: seedTokens({ description: '' }),
  30. },
  31. ];
  32. test('compact - single line', () => {
  33. const tokenize = descriptionTokenizer('compact');
  34. const input = seedSpec({ source: sourceSingle });
  35. const output = seedSpec({ source: sourceSingle, description: 'one two' });
  36. expect(tokenize(input)).toEqual(output);
  37. });
  38. test('compact - multiple lines', () => {
  39. const tokenize = descriptionTokenizer('compact');
  40. const input = seedSpec({ source: sourceMultiple });
  41. const output = seedSpec({
  42. source: sourceMultiple,
  43. description: 'one two three four',
  44. });
  45. expect(tokenize(input)).toEqual(output);
  46. });
  47. test('preserve - multiple lines', () => {
  48. const tokenize = descriptionTokenizer('preserve');
  49. const input = seedSpec({ source: sourceMultiple });
  50. const output = seedSpec({
  51. source: sourceMultiple,
  52. description: 'one two \n\n three four\n',
  53. });
  54. expect(tokenize(input)).toEqual(output);
  55. });
  56. test('preserve - one-liner', () => {
  57. const tokenize = descriptionTokenizer('preserve');
  58. const input = seedSpec({
  59. source: [
  60. {
  61. number: 1,
  62. source: '...',
  63. tokens: seedTokens({
  64. delimiter: '/**',
  65. postDelimiter: ' ',
  66. description: 'description',
  67. end: '*/',
  68. }),
  69. },
  70. ],
  71. });
  72. const output = seedSpec({
  73. description: 'description',
  74. source: [
  75. {
  76. number: 1,
  77. source: '...',
  78. tokens: seedTokens({
  79. delimiter: '/**',
  80. postDelimiter: ' ',
  81. description: 'description',
  82. end: '*/',
  83. }),
  84. },
  85. ],
  86. });
  87. expect(tokenize(input)).toEqual(output);
  88. });
  89. test('preserve - leading empty lines', () => {
  90. const source = [
  91. {
  92. number: 1,
  93. source: '...',
  94. tokens: seedTokens({ delimiter: '/**' }),
  95. },
  96. {
  97. number: 2,
  98. source: '...',
  99. tokens: seedTokens(),
  100. },
  101. {
  102. number: 3,
  103. source: '...',
  104. tokens: seedTokens({ description: ' line 1 ' }),
  105. },
  106. {
  107. number: 4,
  108. source: '...',
  109. tokens: seedTokens({ description: ' line 2 ' }),
  110. },
  111. {
  112. number: 5,
  113. source: '...',
  114. tokens: seedTokens({ description: '' }),
  115. },
  116. ];
  117. const tokenize = descriptionTokenizer('preserve');
  118. const input = seedSpec({ source });
  119. const output = seedSpec({
  120. source,
  121. description: '\n line 1 \n line 2 \n',
  122. });
  123. expect(tokenize(input)).toEqual(output);
  124. });
  125. test('preserve - leading type lines', () => {
  126. const source = [
  127. {
  128. number: 1,
  129. source: '...',
  130. tokens: seedTokens({ delimiter: '/**' }),
  131. },
  132. {
  133. number: 2,
  134. source: '...',
  135. tokens: seedTokens(),
  136. },
  137. {
  138. number: 3,
  139. source: '...',
  140. tokens: seedTokens({ type: '{function(' }),
  141. },
  142. {
  143. number: 4,
  144. source: '...',
  145. tokens: seedTokens({ type: ' number' }),
  146. },
  147. {
  148. number: 5,
  149. source: '...',
  150. tokens: seedTokens({
  151. type: ')}',
  152. postType: ' ',
  153. description: 'line 1 ',
  154. }),
  155. },
  156. {
  157. number: 6,
  158. source: '...',
  159. tokens: seedTokens({ description: ' line 2 ' }),
  160. },
  161. {
  162. number: 7,
  163. source: '...',
  164. tokens: seedTokens({ description: '' }),
  165. },
  166. ];
  167. const tokenize = descriptionTokenizer('preserve');
  168. const input = seedSpec({ source });
  169. const output = seedSpec({
  170. source,
  171. description: 'line 1 \n line 2 \n',
  172. });
  173. expect(tokenize(input)).toEqual(output);
  174. });
  175. test('custom joiner - single line', () => {
  176. const tokenize = descriptionTokenizer((lines) => {
  177. return lines
  178. .reduce((str, { tokens: { description } }) => {
  179. const trimmed = description.trim();
  180. if (!trimmed) {
  181. return str;
  182. }
  183. return str + ' ' + trimmed;
  184. }, '')
  185. .slice(1);
  186. });
  187. const input = seedSpec({ source: sourceSingle });
  188. const output = seedSpec({ source: sourceSingle, description: 'one two' });
  189. expect(tokenize(input)).toEqual(output);
  190. });
  191. test('custom joiner - multiple lines', () => {
  192. const tokenize = descriptionTokenizer((lines) => {
  193. return lines
  194. .reduce((str, { tokens: { description } }) => {
  195. const trimmed = description.trim();
  196. if (!trimmed) {
  197. return str;
  198. }
  199. return str + ' ' + trimmed;
  200. }, '')
  201. .slice(1);
  202. });
  203. const input = seedSpec({ source: sourceMultiple });
  204. const output = seedSpec({
  205. source: sourceMultiple,
  206. description: 'one two three four',
  207. });
  208. expect(tokenize(input)).toEqual(output);
  209. });