@@ -60,6 +60,18 @@ suite('Shell Edit Utils', () => {
6060 const result = hasStartupCode ( content , '# START' , '# END' , [ 'key1' , 'key2' ] ) ;
6161 assert . strictEqual ( result , false ) ;
6262 } ) ;
63+
64+ test ( 'should handle Windows line endings (CRLF) correctly' , ( ) => {
65+ const content = 'content\r\n# START\r\nsome key content\r\n# END\r\nmore content' ;
66+ const result = hasStartupCode ( content , '# START' , '# END' , [ 'key' ] ) ;
67+ assert . strictEqual ( result , true ) ;
68+ } ) ;
69+
70+ test ( 'should handle mixed line endings correctly' , ( ) => {
71+ const content = 'content\n# START\r\nsome key content\n# END\r\nmore content' ;
72+ const result = hasStartupCode ( content , '# START' , '# END' , [ 'key' ] ) ;
73+ assert . strictEqual ( result , true ) ;
74+ } ) ;
6375 } ) ;
6476
6577 suite ( 'insertStartupCode' , ( ) => {
@@ -122,6 +134,30 @@ suite('Shell Edit Utils', () => {
122134
123135 assert . strictEqual ( result , expected ) ;
124136 } ) ;
137+
138+ test ( 'should handle Windows line endings (CRLF) correctly' , ( ) => {
139+ const content = 'before\r\n# START\r\nold code\r\n# END\r\nafter' ;
140+ const start = '# START' ;
141+ const end = '# END' ;
142+ const code = 'new code' ;
143+
144+ const result = insertStartupCode ( content , start , end , code ) ;
145+ const expected = 'before\r\n# START\r\nnew code\r\n# END\r\nafter' ;
146+
147+ assert . strictEqual ( result , expected ) ;
148+ } ) ;
149+
150+ test ( 'should preserve original line ending style when inserting' , ( ) => {
151+ // Content with Windows line endings
152+ const contentWindows = 'before\r\n# START\r\nold code\r\n# END\r\nafter' ;
153+ const resultWindows = insertStartupCode ( contentWindows , '# START' , '# END' , 'new code' ) ;
154+ assert . ok ( resultWindows . includes ( '\r\n' ) , 'Windows line endings should be preserved' ) ;
155+
156+ // Content with Unix line endings
157+ const contentUnix = 'before\n# START\nold code\n# END\nafter' ;
158+ const resultUnix = insertStartupCode ( contentUnix , '# START' , '# END' , 'new code' ) ;
159+ assert . ok ( ! resultUnix . includes ( '\r\n' ) , 'Unix line endings should be preserved' ) ;
160+ } ) ;
125161 } ) ;
126162
127163 suite ( 'removeStartupCode' , ( ) => {
@@ -176,5 +212,24 @@ suite('Shell Edit Utils', () => {
176212 const expected = 'before content' ;
177213 assert . strictEqual ( result , expected ) ;
178214 } ) ;
215+
216+ test ( 'should handle Windows line endings (CRLF) correctly' , ( ) => {
217+ const content = 'before\r\n# START\r\ncode to remove\r\n# END\r\nafter' ;
218+ const result = removeStartupCode ( content , '# START' , '# END' ) ;
219+ const expected = 'before\r\nafter' ;
220+ assert . strictEqual ( result , expected ) ;
221+ } ) ;
222+
223+ test ( 'should preserve original line ending style when removing' , ( ) => {
224+ // Content with Windows line endings
225+ const contentWindows = 'before\r\n# START\r\ncode to remove\r\n# END\r\nafter' ;
226+ const resultWindows = removeStartupCode ( contentWindows , '# START' , '# END' ) ;
227+ assert . ok ( resultWindows . includes ( '\r\n' ) , 'Windows line endings should be preserved' ) ;
228+
229+ // Content with Unix line endings
230+ const contentUnix = 'before\n# START\ncode to remove\n# END\nafter' ;
231+ const resultUnix = removeStartupCode ( contentUnix , '# START' , '# END' ) ;
232+ assert . ok ( ! resultUnix . includes ( '\r\n' ) , 'Unix line endings should be preserved' ) ;
233+ } ) ;
179234 } ) ;
180235} ) ;
0 commit comments