Fix bad matching bug with empty lines

This commit is contained in:
Matt Rubens
2024-12-17 09:28:50 -05:00
parent 800db618bb
commit 38f33de642
2 changed files with 18 additions and 1 deletions

View File

@@ -1054,6 +1054,23 @@ function sum(a, b) {
expect(result.content).toBe('function sum(a, b) {\n return a + b + 1;\n}')
}
})
it('should not exact match empty lines', () => {
const originalContent = 'function sum(a, b) {\n\n return a + b;\n}'
const diffContent = `test.ts
<<<<<<< SEARCH
function sum(a, b) {
=======
import { a } from "a";
function sum(a, b) {
>>>>>>> REPLACE`
const result = strategy.applyDiff(originalContent, diffContent)
expect(result.success).toBe(true)
if (result.success) {
expect(result.content).toBe('import { a } from "a";\nfunction sum(a, b) {\n\n return a + b;\n}')
}
})
})
describe('line-constrained search', () => {

View File

@@ -33,7 +33,7 @@ function levenshteinDistance(a: string, b: string): number {
}
function getSimilarity(original: string, search: string): number {
if (original === '' || search === '') {
if (search === '') {
return 1;
}