|
2 | 2 | formatPromptText, |
3 | 3 | __test__ |
4 | 4 | } from "../../web/js/auto-formatter.js"; |
| 5 | +import { settingValues } from "../../web/js/settings.js"; |
5 | 6 |
|
6 | 7 | const { |
7 | 8 | shouldAutoFormat |
@@ -44,37 +45,102 @@ describe('AutoFormatter Functions', () => { |
44 | 45 | }); |
45 | 46 |
|
46 | 47 | describe('formatPromptText', () => { |
47 | | - test('should format text by adding comma and space after tags', () => { |
48 | | - const input = 'tag1,tag2,tag3'; |
49 | | - const expected = 'tag1, tag2, tag3, '; |
50 | | - expect(formatPromptText(input)).toBe(expected); |
51 | | - }); |
| 48 | + // Store original setting value to restore after tests |
| 49 | + const originalUseTrailingComma = settingValues.useTrailingComma; |
52 | 50 |
|
53 | | - test('should remove extra spaces around tags', () => { |
54 | | - const input = ' tag1 , tag2 '; |
55 | | - const expected = 'tag1, tag2, '; |
56 | | - expect(formatPromptText(input)).toBe(expected); |
| 51 | + afterEach(() => { |
| 52 | + // Restore original setting after each test |
| 53 | + settingValues.useTrailingComma = originalUseTrailingComma; |
57 | 54 | }); |
58 | 55 |
|
59 | | - test('should preserve special syntax like weights', () => { |
60 | | - const input = '(tag1:1.2), [tag2]'; |
61 | | - // Note: The current implementation splits by comma. |
62 | | - // If the input is "(tag1:1.2), [tag2]", it splits into "(tag1:1.2)" and "[tag2]". |
63 | | - // Then joins with ", ". |
64 | | - const expected = '(tag1:1.2), [tag2], '; |
65 | | - expect(formatPromptText(input)).toBe(expected); |
66 | | - }); |
| 56 | + describe('with useTrailingComma enabled', () => { |
| 57 | + beforeEach(() => { |
| 58 | + settingValues.useTrailingComma = true; |
| 59 | + }); |
| 60 | + |
| 61 | + test('should format text by adding comma and space after tags', () => { |
| 62 | + const input = 'tag1,tag2,tag3'; |
| 63 | + const expected = 'tag1, tag2, tag3, '; |
| 64 | + expect(formatPromptText(input)).toBe(expected); |
| 65 | + }); |
| 66 | + |
| 67 | + test('should remove extra spaces around tags', () => { |
| 68 | + const input = ' tag1 , tag2 '; |
| 69 | + const expected = 'tag1, tag2, '; |
| 70 | + expect(formatPromptText(input)).toBe(expected); |
| 71 | + }); |
| 72 | + |
| 73 | + test('should preserve special syntax like weights', () => { |
| 74 | + const input = '(tag1:1.2), [tag2]'; |
| 75 | + // Note: The current implementation splits by comma. |
| 76 | + // If the input is "(tag1:1.2), [tag2]", it splits into "(tag1:1.2)" and "[tag2]". |
| 77 | + // Then joins with ", ". |
| 78 | + const expected = '(tag1:1.2), [tag2], '; |
| 79 | + expect(formatPromptText(input)).toBe(expected); |
| 80 | + }); |
| 81 | + |
| 82 | + test('should handle multiple lines', () => { |
| 83 | + const input = 'tag1, tag2\ntag3, tag4'; |
| 84 | + const expected = 'tag1, tag2, \ntag3, tag4, '; |
| 85 | + expect(formatPromptText(input)).toBe(expected); |
| 86 | + }); |
| 87 | + |
| 88 | + test('should keep empty lines unchanged', () => { |
| 89 | + const input = 'tag1, tag2\n\ntag3, tag4'; |
| 90 | + const expected = 'tag1, tag2, \n\ntag3, tag4, '; |
| 91 | + expect(formatPromptText(input)).toBe(expected); |
| 92 | + }); |
67 | 93 |
|
68 | | - test('should handle multiple lines', () => { |
69 | | - const input = 'tag1, tag2\ntag3, tag4'; |
70 | | - const expected = 'tag1, tag2, \ntag3, tag4, '; |
71 | | - expect(formatPromptText(input)).toBe(expected); |
| 94 | + test('should not modify text that already has trailing comma', () => { |
| 95 | + const input = 'tag1, tag2, '; |
| 96 | + const expected = 'tag1, tag2, '; |
| 97 | + expect(formatPromptText(input)).toBe(expected); |
| 98 | + }); |
72 | 99 | }); |
73 | 100 |
|
74 | | - test('should keep empty lines unchanged', () => { |
75 | | - const input = 'tag1, tag2\n\ntag3, tag4'; |
76 | | - const expected = 'tag1, tag2, \n\ntag3, tag4, '; |
77 | | - expect(formatPromptText(input)).toBe(expected); |
| 101 | + describe('with useTrailingComma disabled', () => { |
| 102 | + beforeEach(() => { |
| 103 | + settingValues.useTrailingComma = false; |
| 104 | + }); |
| 105 | + |
| 106 | + test('should format text by adding comma and space after tags without trailing comma', () => { |
| 107 | + const input = 'tag1,tag2,tag3'; |
| 108 | + const expected = 'tag1, tag2, tag3'; |
| 109 | + expect(formatPromptText(input)).toBe(expected); |
| 110 | + }); |
| 111 | + |
| 112 | + test('should remove extra spaces around tags without trailing comma', () => { |
| 113 | + const input = ' tag1 , tag2 '; |
| 114 | + const expected = 'tag1, tag2'; |
| 115 | + expect(formatPromptText(input)).toBe(expected); |
| 116 | + }); |
| 117 | + |
| 118 | + test('should preserve special syntax like weights without trailing comma', () => { |
| 119 | + const input = '(tag1:1.2), [tag2]'; |
| 120 | + // Note: The current implementation splits by comma. |
| 121 | + // If the input is "(tag1:1.2), [tag2]", it splits into "(tag1:1.2)" and "[tag2]". |
| 122 | + // Then joins with ", ". |
| 123 | + const expected = '(tag1:1.2), [tag2]'; |
| 124 | + expect(formatPromptText(input)).toBe(expected); |
| 125 | + }); |
| 126 | + |
| 127 | + test('should handle multiple lines without trailing comma', () => { |
| 128 | + const input = 'tag1, tag2\ntag3, tag4'; |
| 129 | + const expected = 'tag1, tag2\ntag3, tag4'; |
| 130 | + expect(formatPromptText(input)).toBe(expected); |
| 131 | + }); |
| 132 | + |
| 133 | + test('should keep empty lines unchanged without trailing comma', () => { |
| 134 | + const input = 'tag1, tag2\n\ntag3, tag4'; |
| 135 | + const expected = 'tag1, tag2\n\ntag3, tag4'; |
| 136 | + expect(formatPromptText(input)).toBe(expected); |
| 137 | + }); |
| 138 | + |
| 139 | + test('should remove existing trailing comma when disabled', () => { |
| 140 | + const input = 'tag1, tag2, '; |
| 141 | + const expected = 'tag1, tag2'; |
| 142 | + expect(formatPromptText(input)).toBe(expected); |
| 143 | + }); |
78 | 144 | }); |
79 | 145 |
|
80 | 146 | test('should handle empty input', () => { |
|
0 commit comments