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