@@ -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,20 +50,73 @@ 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' , ( ) => {
48106 // Store original setting value to restore after tests
49107 const originalUseTrailingComma = settingValues . useTrailingComma ;
108+ const originalTrimSurroundingSpaces = settingValues . trimSurroundingSpaces ;
50109
51110 afterEach ( ( ) => {
52111 // Restore original setting after each test
53112 settingValues . useTrailingComma = originalUseTrailingComma ;
113+ settingValues . trimSurroundingSpaces = originalTrimSurroundingSpaces ;
54114 } ) ;
55115
56116 describe ( 'with useTrailingComma enabled' , ( ) => {
57117 beforeEach ( ( ) => {
58118 settingValues . useTrailingComma = true ;
119+ settingValues . trimSurroundingSpaces = false ;
59120 } ) ;
60121
61122 test ( 'should format text by adding comma and space after tags' , ( ) => {
@@ -101,6 +162,7 @@ describe('AutoFormatter Functions', () => {
101162 describe ( 'with useTrailingComma disabled' , ( ) => {
102163 beforeEach ( ( ) => {
103164 settingValues . useTrailingComma = false ;
165+ settingValues . trimSurroundingSpaces = false ;
104166 } ) ;
105167
106168 test ( 'should format text by adding comma and space after tags without trailing comma' , ( ) => {
@@ -143,6 +205,59 @@ describe('AutoFormatter Functions', () => {
143205 } ) ;
144206 } ) ;
145207
208+ describe ( 'with trimSurroundingSpaces enabled' , ( ) => {
209+ beforeEach ( ( ) => {
210+ settingValues . trimSurroundingSpaces = true ;
211+ settingValues . useTrailingComma = false ;
212+ } ) ;
213+
214+ test ( 'should remove trailing newlines and spaces' , ( ) => {
215+ const input = 'tag1, tag2\n\n ' ;
216+ const expected = 'tag1, tag2' ;
217+ expect ( formatPromptText ( input ) ) . toBe ( expected ) ;
218+ } ) ;
219+
220+ test ( 'should remove leading newlines and spaces' , ( ) => {
221+ const input = ' \n\ntag1, tag2' ;
222+ const expected = 'tag1, tag2' ;
223+ expect ( formatPromptText ( input ) ) . toBe ( expected ) ;
224+ } ) ;
225+
226+ test ( 'should remove both leading and trailing whitespaces but keep middle empty lines' , ( ) => {
227+ const input = ' \n\ntag1\n\ntag2\n\n ' ;
228+ const expected = 'tag1\n\ntag2' ;
229+ expect ( formatPromptText ( input ) ) . toBe ( expected ) ;
230+ } ) ;
231+
232+ test ( 'should return empty string if input is only whitespace' , ( ) => {
233+ const input = ' \n ' ;
234+ expect ( formatPromptText ( input ) ) . toBe ( '' ) ;
235+ } ) ;
236+ } ) ;
237+
238+ describe ( 'with trimSurroundingSpaces disabled' , ( ) => {
239+ beforeEach ( ( ) => {
240+ settingValues . trimSurroundingSpaces = false ;
241+ settingValues . useTrailingComma = false ;
242+ } ) ;
243+
244+ test ( 'should preserve trailing newlines' , ( ) => {
245+ const input = 'tag1, tag2\n\n' ;
246+ const expected = 'tag1, tag2\n\n' ;
247+ expect ( formatPromptText ( input ) ) . toBe ( expected ) ;
248+ } ) ;
249+
250+ test ( 'should preserve leading spaces (as first line content)' , ( ) => {
251+ const input = ' \ntag1' ;
252+ const expected = '\ntag1' ;
253+ expect ( formatPromptText ( input ) ) . toBe ( expected ) ;
254+ } ) ;
255+
256+ test ( 'should handle input with only spaces' , ( ) => {
257+ expect ( formatPromptText ( ' ' ) ) . toBe ( ' ' ) ;
258+ } ) ;
259+ } ) ;
260+
146261 test ( 'should handle empty input' , ( ) => {
147262 expect ( formatPromptText ( '' ) ) . toBe ( '' ) ;
148263 expect ( formatPromptText ( null ) ) . toBe ( null ) ;
0 commit comments