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.

transforms-align.spec.ts 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165
  1. import align from '../../src/transforms/align';
  2. import getParser, { Parser } from '../../src/parser/index';
  3. import getStringifier, { Stringifier } from '../../src/stringifier/index';
  4. let parse: Parser;
  5. let stringify: Stringifier;
  6. beforeEach(() => {
  7. parse = getParser();
  8. stringify = getStringifier();
  9. });
  10. test('multiline', () => {
  11. const source = `
  12. /**
  13. * Description may go
  14. * over multiple lines followed by @tags
  15. *
  16. * @some-tag {some-type} some-name description line 1
  17. * @another-tag {another-type} another-name description line 1
  18. description line 2
  19. * description line 3
  20. */`;
  21. const expected = `
  22. /**
  23. * Description may go
  24. * over multiple lines followed by @tags
  25. *
  26. * @some-tag {some-type} some-name description line 1
  27. * @another-tag {another-type} another-name description line 1
  28. description line 2
  29. * description line 3
  30. */`.slice(1);
  31. const parsed = parse(source);
  32. const aligned = align()(parsed[0]);
  33. const out = stringify(aligned);
  34. // console.log(inspect(aligned));
  35. expect(out).toBe(expected);
  36. });
  37. test('one-liner', () => {
  38. const source = ` /** @tag {type} name description */`;
  39. const parsed = parse(source);
  40. const out = stringify(align()(parsed[0]));
  41. expect(out).toBe(source);
  42. });
  43. test('same line open', () => {
  44. const source = `
  45. /** @tag {type} name description
  46. */`.slice(1);
  47. const parsed = parse(source);
  48. const out = stringify(align()(parsed[0]));
  49. expect(out).toBe(source);
  50. });
  51. test('same line close', () => {
  52. const source = `
  53. /**
  54. * @tag {type} name description */`;
  55. const expected = `
  56. /**
  57. * @tag {type} name description */`.slice(1);
  58. const parsed = parse(source);
  59. const aligned = align()(parsed[0]);
  60. const out = stringify(aligned);
  61. expect(out).toBe(expected);
  62. });
  63. test('spec source referencing', () => {
  64. const parsed = parse(`/** @tag {type} name Description */`);
  65. const block = align()(parsed[0]);
  66. expect(block.tags[0].source[0] === block.source[0]).toBe(true);
  67. });
  68. test('block source clonning', () => {
  69. const parsed = parse(`/** @tag {type} name Description */`);
  70. const block = align()(parsed[0]);
  71. parsed[0].source[0].tokens.description = 'test';
  72. expect(block.source[0].tokens.description).toBe('Description ');
  73. });
  74. test('ignore right whitespace', () => {
  75. const source = `
  76. /**
  77. * Description may go
  78. * over multiple lines followed by @tags
  79. * @private
  80. * @param {string} name
  81. * @param {any} value the value parameter
  82. *
  83. */`.slice(1);
  84. const expected = `
  85. /**
  86. * Description may go
  87. * over multiple lines followed by @tags
  88. * @private
  89. * @param {string} name
  90. * @param {any} value the value parameter
  91. *
  92. */`.slice(1);
  93. const parsed = parse(source);
  94. const aligned = align()(parsed[0]);
  95. const stringified = stringify(aligned);
  96. expect(stringified).toEqual(expected);
  97. });
  98. test('collapse postDelimiter', () => {
  99. const source = `
  100. /**
  101. * Description may go
  102. * over multiple lines followed by @tags
  103. * @param {string} name the name parameter
  104. * @param {any} value the value parameter
  105. */`.slice(1);
  106. const expected = `
  107. /**
  108. * Description may go
  109. * over multiple lines followed by @tags
  110. * @param {string} name the name parameter
  111. * @param {any} value the value parameter
  112. */`.slice(1);
  113. const parsed = parse(source);
  114. const aligned = align()(parsed[0]);
  115. const stringified = stringify(aligned);
  116. expect(stringified).toEqual(expected);
  117. });
  118. test('keep carriage returns', () => {
  119. const source = `
  120. /**\r\r
  121. * Description may go\r
  122. * over multiple lines followed by @tags\r
  123. * @param {string} name the name parameter\r
  124. * @param {any} value\r
  125. */\r`.slice(1);
  126. const expected = `
  127. /**\r\r
  128. * Description may go\r
  129. * over multiple lines followed by @tags\r
  130. * @param {string} name the name parameter\r
  131. * @param {any} value\r
  132. */\r`.slice(1);
  133. const parsed = parse(source);
  134. const aligned = align()(parsed[0]);
  135. const stringified = stringify(aligned);
  136. expect(stringified).toEqual(expected);
  137. });