mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-28 05:55:17 -07:00
Fix newline insertion bug in replace tool (#18595)
This commit is contained in:
@@ -372,6 +372,43 @@ describe('EditTool', () => {
|
||||
expect(result.newContent).toBe(expectedContent);
|
||||
expect(result.occurrences).toBe(1);
|
||||
});
|
||||
|
||||
it('should NOT insert extra newlines when replacing a block preceded by a blank line (regression)', async () => {
|
||||
const content = '\n function oldFunc() {\n // some code\n }';
|
||||
const result = await calculateReplacement(mockConfig, {
|
||||
params: {
|
||||
file_path: 'test.js',
|
||||
instruction: 'test',
|
||||
old_string: 'function oldFunc() {\n // some code\n }', // Two spaces after function to trigger regex
|
||||
new_string: 'function newFunc() {\n // new code\n}', // Unindented
|
||||
},
|
||||
currentContent: content,
|
||||
abortSignal,
|
||||
});
|
||||
|
||||
// The blank line at the start should be preserved as-is,
|
||||
// and the discovered indentation (2 spaces) should be applied to each line.
|
||||
const expectedContent = '\n function newFunc() {\n // new code\n }';
|
||||
expect(result.newContent).toBe(expectedContent);
|
||||
});
|
||||
|
||||
it('should NOT insert extra newlines in flexible replacement when old_string starts with a blank line (regression)', async () => {
|
||||
const content = ' // some comment\n\n function oldFunc() {}';
|
||||
const result = await calculateReplacement(mockConfig, {
|
||||
params: {
|
||||
file_path: 'test.js',
|
||||
instruction: 'test',
|
||||
old_string: '\nfunction oldFunc() {}',
|
||||
new_string: '\n function newFunc() {}', // Include desired indentation
|
||||
},
|
||||
currentContent: content,
|
||||
abortSignal,
|
||||
});
|
||||
|
||||
// The blank line at the start is preserved, and the new block is inserted.
|
||||
const expectedContent = ' // some comment\n\n function newFunc() {}';
|
||||
expect(result.newContent).toBe(expectedContent);
|
||||
});
|
||||
});
|
||||
|
||||
describe('validateToolParams', () => {
|
||||
|
||||
Reference in New Issue
Block a user