@@ -228,6 +228,196 @@ function hello() {
228228 const result = strategy . applyDiff ( originalContent , diffContent )
229229 expect ( result ) . toBe ( ' onScroll={() => updateHighlights()}\n onDragOver={(e) => {\n e.preventDefault()\n e.stopPropagation()\n }}' )
230230 } )
231+
232+ it ( 'should handle varying indentation levels correctly' , ( ) => {
233+ const originalContent = `
234+ class Example {
235+ constructor() {
236+ this.value = 0;
237+ if (true) {
238+ this.init();
239+ }
240+ }
241+ }` . trim ( ) ;
242+
243+ const diffContent = `test.ts
244+ <<<<<<< SEARCH
245+ class Example {
246+ constructor() {
247+ this.value = 0;
248+ if (true) {
249+ this.init();
250+ }
251+ }
252+ }
253+ =======
254+ class Example {
255+ constructor() {
256+ this.value = 1;
257+ if (true) {
258+ this.init();
259+ this.setup();
260+ this.validate();
261+ }
262+ }
263+ }
264+ >>>>>>> REPLACE` . trim ( ) ;
265+
266+ const result = strategy . applyDiff ( originalContent , diffContent ) ;
267+ expect ( result ) . toBe ( `
268+ class Example {
269+ constructor() {
270+ this.value = 1;
271+ if (true) {
272+ this.init();
273+ this.setup();
274+ this.validate();
275+ }
276+ }
277+ }` . trim ( ) ) ;
278+ } ) ;
279+
280+ it ( 'should handle mixed indentation styles in the same file' , ( ) => {
281+ const originalContent = `class Example {
282+ constructor() {
283+ this.value = 0;
284+ if (true) {
285+ this.init();
286+ }
287+ }
288+ }` . trim ( ) ;
289+ const diffContent = `test.ts
290+ <<<<<<< SEARCH
291+ constructor() {
292+ this.value = 0;
293+ if (true) {
294+ this.init();
295+ }
296+ }
297+ =======
298+ constructor() {
299+ this.value = 1;
300+ if (true) {
301+ this.init();
302+ this.validate();
303+ }
304+ }
305+ >>>>>>> REPLACE` ;
306+
307+ const result = strategy . applyDiff ( originalContent , diffContent ) ;
308+ expect ( result ) . toBe ( `class Example {
309+ constructor() {
310+ this.value = 1;
311+ if (true) {
312+ this.init();
313+ this.validate();
314+ }
315+ }
316+ }` ) ;
317+ } ) ;
318+
319+ it ( 'should handle Python-style significant whitespace' , ( ) => {
320+ const originalContent = `def example():
321+ if condition:
322+ do_something()
323+ for item in items:
324+ process(item)
325+ return True` . trim ( ) ;
326+ const diffContent = `test.ts
327+ <<<<<<< SEARCH
328+ if condition:
329+ do_something()
330+ for item in items:
331+ process(item)
332+ =======
333+ if condition:
334+ do_something()
335+ while items:
336+ item = items.pop()
337+ process(item)
338+ >>>>>>> REPLACE` ;
339+
340+ const result = strategy . applyDiff ( originalContent , diffContent ) ;
341+ expect ( result ) . toBe ( `def example():
342+ if condition:
343+ do_something()
344+ while items:
345+ item = items.pop()
346+ process(item)
347+ return True` ) ;
348+ } ) ;
349+
350+ it ( 'should preserve empty lines with indentation' , ( ) => {
351+ const originalContent = `function test() {
352+ const x = 1;
353+
354+ if (x) {
355+ return true;
356+ }
357+ }` . trim ( ) ;
358+ const diffContent = `test.ts
359+ <<<<<<< SEARCH
360+ const x = 1;
361+
362+ if (x) {
363+ =======
364+ const x = 1;
365+
366+ // Check x
367+ if (x) {
368+ >>>>>>> REPLACE` ;
369+
370+ const result = strategy . applyDiff ( originalContent , diffContent ) ;
371+ expect ( result ) . toBe ( `function test() {
372+ const x = 1;
373+
374+ // Check x
375+ if (x) {
376+ return true;
377+ }
378+ }` ) ;
379+ } ) ;
380+
381+ it ( 'should handle indentation when replacing entire blocks' , ( ) => {
382+ const originalContent = `class Test {
383+ method() {
384+ if (true) {
385+ console.log("test");
386+ }
387+ }
388+ }` . trim ( ) ;
389+ const diffContent = `test.ts
390+ <<<<<<< SEARCH
391+ method() {
392+ if (true) {
393+ console.log("test");
394+ }
395+ }
396+ =======
397+ method() {
398+ try {
399+ if (true) {
400+ console.log("test");
401+ }
402+ } catch (e) {
403+ console.error(e);
404+ }
405+ }
406+ >>>>>>> REPLACE` ;
407+
408+ const result = strategy . applyDiff ( originalContent , diffContent ) ;
409+ expect ( result ) . toBe ( `class Test {
410+ method() {
411+ try {
412+ if (true) {
413+ console.log("test");
414+ }
415+ } catch (e) {
416+ console.error(e);
417+ }
418+ }
419+ }` ) ;
420+ } ) ;
231421 } )
232422
233423 describe ( 'fuzzy matching' , ( ) => {
0 commit comments