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.

spacer-description-joiner.spec.ts 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. import { getJoiner } from '../../src/parser/tokenizers/description';
  2. import { Line } from '../../src/primitives';
  3. import { seedTokens } from '../../src/util';
  4. const source: Line[] = [
  5. {
  6. number: 1,
  7. source: ' /**',
  8. tokens: seedTokens({
  9. start: ' ',
  10. delimiter: '/**',
  11. }),
  12. },
  13. {
  14. number: 2,
  15. source: ' * ',
  16. tokens: seedTokens({
  17. start: ' ',
  18. delimiter: '*',
  19. postDelimiter: ' ',
  20. }),
  21. },
  22. {
  23. number: 3,
  24. source: ' * Description first line\twith\ttabs ',
  25. tokens: seedTokens({
  26. start: ' ',
  27. delimiter: '*',
  28. postDelimiter: ' ',
  29. description: 'Description first line\twith\ttabs ',
  30. }),
  31. },
  32. {
  33. number: 4,
  34. source: ' * second line ',
  35. tokens: seedTokens({
  36. start: ' ',
  37. delimiter: '*',
  38. postDelimiter: ' ',
  39. description: 'second line ',
  40. }),
  41. },
  42. {
  43. number: 5,
  44. source: ' * ',
  45. tokens: seedTokens({
  46. start: ' ',
  47. delimiter: '*',
  48. postDelimiter: ' ',
  49. }),
  50. },
  51. {
  52. number: 6,
  53. source: ' * third line ',
  54. tokens: seedTokens({
  55. start: ' ',
  56. delimiter: '*',
  57. postDelimiter: ' ',
  58. description: 'third line ',
  59. }),
  60. },
  61. {
  62. number: 7,
  63. source: ' */',
  64. tokens: seedTokens({
  65. start: ' ',
  66. end: '*/',
  67. }),
  68. },
  69. ];
  70. test('compact', () => {
  71. const joined = getJoiner('compact')(source);
  72. expect(joined).toBe(
  73. 'Description first line\twith\ttabs second line third line'
  74. );
  75. });
  76. test('preserve', () => {
  77. const joined = getJoiner('preserve')(source);
  78. expect(joined).toBe(
  79. ' \n Description first line\twith\ttabs \n second line \n \n third line '
  80. );
  81. });
  82. test('preserve - empty', () => {
  83. const joined = getJoiner('preserve')([]);
  84. expect(joined).toBe('');
  85. });
  86. test('preserve - no delimiter', () => {
  87. const joined = getJoiner('preserve')([
  88. {
  89. number: 1,
  90. source: '...',
  91. tokens: seedTokens({
  92. start: ' ',
  93. delimiter: '',
  94. postDelimiter: '',
  95. description: 'line with no delimiter',
  96. }),
  97. },
  98. ]);
  99. expect(joined).toBe(' line with no delimiter');
  100. });
  101. test('custom', () => {
  102. const spacerFn = (source: Line[]) =>
  103. source
  104. .map(({ tokens: { description } }) =>
  105. description.replace(/\s+/g, ' ').trim().toUpperCase()
  106. )
  107. .filter((s) => s !== '')
  108. .join(' ');
  109. const joined = getJoiner(spacerFn)(source);
  110. expect(joined).toBe(
  111. 'DESCRIPTION FIRST LINE WITH TABS SECOND LINE THIRD LINE'
  112. );
  113. });