Compare commits
1 Commits
main
...
fix_251219
| Author | SHA1 | Date | |
|---|---|---|---|
| 9231f09176 |
@@ -26,11 +26,7 @@ describe('Edit Parsers', () => {
|
|||||||
describe('parseSearchReplaceBlocks', () => {
|
describe('parseSearchReplaceBlocks', () => {
|
||||||
it('should parse marker format blocks', () => {
|
it('should parse marker format blocks', () => {
|
||||||
const content = `
|
const content = `
|
||||||
<<<<<<< SEARCH
|
|
||||||
old content
|
old content
|
||||||
=======
|
|
||||||
new content
|
|
||||||
>>>>>>> REPLACE
|
|
||||||
`;
|
`;
|
||||||
const blocks = parseSearchReplaceBlocks(content);
|
const blocks = parseSearchReplaceBlocks(content);
|
||||||
expect(blocks).toHaveLength(1);
|
expect(blocks).toHaveLength(1);
|
||||||
@@ -40,17 +36,8 @@ new content
|
|||||||
|
|
||||||
it('should parse multiple marker format blocks', () => {
|
it('should parse multiple marker format blocks', () => {
|
||||||
const content = `
|
const content = `
|
||||||
<<<<<<< SEARCH
|
|
||||||
first old
|
first old
|
||||||
=======
|
|
||||||
first new
|
|
||||||
>>>>>>> REPLACE
|
|
||||||
|
|
||||||
<<<<<<< SEARCH
|
|
||||||
second old
|
second old
|
||||||
=======
|
|
||||||
second new
|
|
||||||
>>>>>>> REPLACE
|
|
||||||
`;
|
`;
|
||||||
const blocks = parseSearchReplaceBlocks(content);
|
const blocks = parseSearchReplaceBlocks(content);
|
||||||
expect(blocks).toHaveLength(2);
|
expect(blocks).toHaveLength(2);
|
||||||
@@ -81,9 +68,7 @@ second new
|
|||||||
|
|
||||||
describe('createSearchReplaceEdit', () => {
|
describe('createSearchReplaceEdit', () => {
|
||||||
it('should create search-replace edit', () => {
|
it('should create search-replace edit', () => {
|
||||||
const blocks: SearchReplaceBlock[] = [
|
const blocks: SearchReplaceBlock[] = [{ search: 'old', replace: 'new' }];
|
||||||
{ search: 'old', replace: 'new' },
|
|
||||||
];
|
|
||||||
const edit = createSearchReplaceEdit('/test/file.ts', blocks);
|
const edit = createSearchReplaceEdit('/test/file.ts', blocks);
|
||||||
expect(edit.mode).toBe('search-replace');
|
expect(edit.mode).toBe('search-replace');
|
||||||
expect(edit.blocks).toHaveLength(1);
|
expect(edit.blocks).toHaveLength(1);
|
||||||
@@ -124,7 +109,9 @@ new
|
|||||||
|
|
||||||
it('should trim trailing whitespace', () => {
|
it('should trim trailing whitespace', () => {
|
||||||
const input = 'line1 \nline2 ';
|
const input = 'line1 \nline2 ';
|
||||||
const result = normalizeSearchString(input, { trimTrailingWhitespace: true });
|
const result = normalizeSearchString(input, {
|
||||||
|
trimTrailingWhitespace: true,
|
||||||
|
});
|
||||||
expect(result).toBe('line1\nline2');
|
expect(result).toBe('line1\nline2');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -331,12 +318,15 @@ describe('Edit Applier', () => {
|
|||||||
await fs.writeFile(file1, 'content 1');
|
await fs.writeFile(file1, 'content 1');
|
||||||
await fs.writeFile(file2, 'content 2');
|
await fs.writeFile(file2, 'content 2');
|
||||||
|
|
||||||
const result = await applyBatchEdits({
|
const result = await applyBatchEdits(
|
||||||
edits: [
|
{
|
||||||
createWholeFileEdit(file1, 'new content 1'),
|
edits: [
|
||||||
createWholeFileEdit(file2, 'new content 2'),
|
createWholeFileEdit(file1, 'new content 1'),
|
||||||
],
|
createWholeFileEdit(file2, 'new content 2'),
|
||||||
}, { runDiagnostics: false });
|
],
|
||||||
|
},
|
||||||
|
{ runDiagnostics: false },
|
||||||
|
);
|
||||||
|
|
||||||
expect(result.success).toBe(true);
|
expect(result.success).toBe(true);
|
||||||
expect(result.results).toHaveLength(2);
|
expect(result.results).toHaveLength(2);
|
||||||
@@ -353,13 +343,16 @@ describe('Edit Applier', () => {
|
|||||||
await fs.writeFile(file1, 'original 1');
|
await fs.writeFile(file1, 'original 1');
|
||||||
await fs.writeFile(file2, 'original 2');
|
await fs.writeFile(file2, 'original 2');
|
||||||
|
|
||||||
const result = await applyBatchEdits({
|
const result = await applyBatchEdits(
|
||||||
edits: [
|
{
|
||||||
createWholeFileEdit(file1, 'new content 1'),
|
edits: [
|
||||||
createSingleSearchReplaceEdit(file2, 'not found', 'replacement'),
|
createWholeFileEdit(file1, 'new content 1'),
|
||||||
],
|
createSingleSearchReplaceEdit(file2, 'not found', 'replacement'),
|
||||||
atomic: true,
|
],
|
||||||
}, { runDiagnostics: false });
|
atomic: true,
|
||||||
|
},
|
||||||
|
{ runDiagnostics: false },
|
||||||
|
);
|
||||||
|
|
||||||
expect(result.success).toBe(false);
|
expect(result.success).toBe(false);
|
||||||
|
|
||||||
@@ -374,12 +367,15 @@ describe('Edit Applier', () => {
|
|||||||
await fs.writeFile(file1, 'line1\nline2');
|
await fs.writeFile(file1, 'line1\nline2');
|
||||||
await fs.writeFile(file2, 'a\nb\nc');
|
await fs.writeFile(file2, 'a\nb\nc');
|
||||||
|
|
||||||
const result = await applyBatchEdits({
|
const result = await applyBatchEdits(
|
||||||
edits: [
|
{
|
||||||
createWholeFileEdit(file1, 'line1\nline2\nline3'),
|
edits: [
|
||||||
createWholeFileEdit(file2, 'x\ny'),
|
createWholeFileEdit(file1, 'line1\nline2\nline3'),
|
||||||
],
|
createWholeFileEdit(file2, 'x\ny'),
|
||||||
}, { runDiagnostics: false });
|
],
|
||||||
|
},
|
||||||
|
{ runDiagnostics: false },
|
||||||
|
);
|
||||||
|
|
||||||
expect(result.success).toBe(true);
|
expect(result.success).toBe(true);
|
||||||
expect(result.totalStats.blocksApplied).toBe(2);
|
expect(result.totalStats.blocksApplied).toBe(2);
|
||||||
|
|||||||
Reference in New Issue
Block a user