Skip to content

Commit 199ee05

Browse files
test: Enhance auto-formatter tests
1 parent 06f0157 commit 199ee05

1 file changed

Lines changed: 58 additions & 0 deletions

File tree

tests/js/auto-formatter.test.js

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,14 @@ describe('AutoFormatter Functions', () => {
1616
inputName
1717
});
1818

19+
// Store original setting value to restore after tests
20+
const originalTrimSurroundingSpaces = settingValues.trimSurroundingSpaces;
21+
22+
afterEach(() => {
23+
// Restore original setting after each test
24+
settingValues.trimSurroundingSpaces = originalTrimSurroundingSpaces;
25+
});
26+
1927
test('should return false for empty text', () => {
2028
expect(shouldAutoFormat('', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
2129
expect(shouldAutoFormat(' ', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
@@ -42,6 +50,56 @@ describe('AutoFormatter Functions', () => {
4250
expect(shouldAutoFormat('hello world', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
4351
expect(shouldAutoFormat('tag1 tag2', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
4452
});
53+
54+
describe('blocklist priority with trimSurroundingSpaces', () => {
55+
test('should prioritize blocklist over trimSurroundingSpaces when disabled', () => {
56+
settingValues.trimSurroundingSpaces = false;
57+
58+
// Blocklisted nodes should return false even with surrounding spaces
59+
expect(shouldAutoFormat(' some code ', mockNodeInfo('Power Puter (rgthree)', 'code'))).toBe(false);
60+
expect(shouldAutoFormat('\nsome code\n', mockNodeInfo('Power Puter (rgthree)', 'code'))).toBe(false);
61+
expect(shouldAutoFormat(' 0,0,0,1,1,1 ', mockNodeInfo('LoraLoaderBlockWeight //Inspire', 'block_vector'))).toBe(false);
62+
});
63+
64+
test('should prioritize blocklist over trimSurroundingSpaces when enabled', () => {
65+
settingValues.trimSurroundingSpaces = true;
66+
67+
// Blocklisted nodes should return false even with trimSurroundingSpaces enabled and surrounding spaces
68+
expect(shouldAutoFormat(' some code ', mockNodeInfo('Power Puter (rgthree)', 'code'))).toBe(false);
69+
expect(shouldAutoFormat('\nsome code\n', mockNodeInfo('Power Puter (rgthree)', 'code'))).toBe(false);
70+
expect(shouldAutoFormat(' function() { } ', mockNodeInfo('Power Puter (rgthree)', 'code'))).toBe(false);
71+
expect(shouldAutoFormat(' 0,0,0,1,1,1 ', mockNodeInfo('LoraLoaderBlockWeight //Inspire', 'block_vector'))).toBe(false);
72+
});
73+
});
74+
75+
describe('trimSurroundingSpaces with non-comma-separated text', () => {
76+
test('should return false for non-comma-separated text when trimSurroundingSpaces is disabled', () => {
77+
settingValues.trimSurroundingSpaces = false;
78+
79+
// Text without word+comma pattern should return false
80+
expect(shouldAutoFormat(' hello world ', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
81+
expect(shouldAutoFormat('\nhello world\n', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
82+
expect(shouldAutoFormat(' tag1 tag2 ', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
83+
});
84+
85+
test('should return true for non-comma-separated text with surrounding spaces when trimSurroundingSpaces is enabled', () => {
86+
settingValues.trimSurroundingSpaces = true;
87+
88+
// Text with surrounding spaces should return true to format (trim them)
89+
expect(shouldAutoFormat(' hello world ', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(true);
90+
expect(shouldAutoFormat('\nhello world\n', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(true);
91+
expect(shouldAutoFormat(' tag1 tag2 ', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(true);
92+
expect(shouldAutoFormat(' \nsome text\n ', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(true);
93+
});
94+
95+
test('should return false for text without surrounding spaces even when trimSurroundingSpaces is enabled', () => {
96+
settingValues.trimSurroundingSpaces = true;
97+
98+
// Text without word+comma pattern and without surrounding spaces should return false
99+
expect(shouldAutoFormat('hello world', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
100+
expect(shouldAutoFormat('tag1 tag2', mockNodeInfo('CLIPTextEncode', 'text'))).toBe(false);
101+
});
102+
});
45103
});
46104

47105
describe('formatPromptText', () => {

0 commit comments

Comments
 (0)