Skip to content

Commit 70ad8cb

Browse files
committed
fix: remove jarowinkler similarity for search and replace
1 parent 148a9ea commit 70ad8cb

File tree

3 files changed

+0
-432
lines changed

3 files changed

+0
-432
lines changed

core/edit/searchAndReplace/findSearchMatch.strategy.test.ts

Lines changed: 0 additions & 95 deletions
Original file line numberDiff line numberDiff line change
@@ -426,101 +426,6 @@ const a = 1;`;
426426
});
427427
});
428428

429-
describe("jaroWinklerFuzzyMatch strategy", () => {
430-
it("should match similar code with variable name differences", () => {
431-
const fileContent = `function calculateTotal(items) {
432-
let sum = 0;
433-
for (const item of items) {
434-
sum += item.price;
435-
}
436-
return sum;
437-
}`;
438-
const searchContent = `function calculateTotal(products) {
439-
let total = 0;
440-
for (const product of products) {
441-
total += product.price;
442-
}
443-
return total;
444-
}`;
445-
446-
const result = findSearchMatch(fileContent, searchContent);
447-
expect(result).not.toBeNull();
448-
expect(result!.strategyName).toBe("jaroWinklerFuzzyMatch");
449-
});
450-
451-
it("should match code with minor typos", () => {
452-
const testCases = [
453-
{
454-
name: "typo in function name",
455-
fileContent: "function getUserName() { return this.name; }",
456-
searchContent: "function getUserNaem() { return this.name; }",
457-
},
458-
{
459-
name: "typo in variable",
460-
fileContent: "const message = 'Hello World';",
461-
searchContent: "const mesage = 'Hello World';",
462-
},
463-
{
464-
name: "missing character",
465-
fileContent: "console.log('Debug info');",
466-
searchContent: "console.log('Debug nfo');",
467-
},
468-
];
469-
470-
testCases.forEach(({ name, fileContent, searchContent }) => {
471-
const result = findSearchMatch(fileContent, searchContent);
472-
expect(result).not.toBeNull();
473-
expect(result!.strategyName).toBe("jaroWinklerFuzzyMatch");
474-
});
475-
});
476-
477-
it("should not match when similarity is too low", () => {
478-
const fileContent = "function add(a, b) { return a + b; }";
479-
const searchContent =
480-
"class Calculator { multiply(x, y) { return x * y; } }";
481-
482-
const result = findSearchMatch(fileContent, searchContent);
483-
expect(result).toBeNull();
484-
});
485-
486-
it("should handle multiline fuzzy matches", () => {
487-
const fileContent = `if (userIsLoggedIn) {
488-
showDashboard();
489-
loadUserData();
490-
}`;
491-
const searchContent = `if (isUserLoggedIn) {
492-
displayDashboard();
493-
fetchUserData();
494-
}`;
495-
496-
const result = findSearchMatch(fileContent, searchContent);
497-
expect(result).not.toBeNull();
498-
expect(result!.strategyName).toBe("jaroWinklerFuzzyMatch");
499-
});
500-
501-
it("should verify replacement with fuzzy matches", () => {
502-
const fileContent = "const userName = 'John';";
503-
const searchContent = "const usrName = 'John';"; // Typo in variable name
504-
const replacement = "const userName = 'Jane';";
505-
506-
const match = findSearchMatch(fileContent, searchContent);
507-
expect(match).not.toBeNull();
508-
expect(match!.strategyName).toBe("jaroWinklerFuzzyMatch");
509-
510-
const result = performReplacement(fileContent, match!, replacement);
511-
expect(result).toBe(replacement);
512-
});
513-
514-
it("should handle edge case with very short strings", () => {
515-
const fileContent = "ab";
516-
const searchContent = "ac";
517-
518-
const result = findSearchMatch(fileContent, searchContent);
519-
// Should not match due to low similarity on short strings
520-
expect(result).toBeNull();
521-
});
522-
});
523-
524429
describe("Empty search content", () => {
525430
it("should always return position 0 for empty search", () => {
526431
const testCases = [

core/edit/searchAndReplace/findSearchMatch.test.ts

Lines changed: 0 additions & 181 deletions
Original file line numberDiff line numberDiff line change
@@ -191,34 +191,6 @@ describe("Empty search content", () => {
191191
});
192192
});
193193

194-
describe("No matches", () => {
195-
it("should return null when search content is not found", () => {
196-
const fileContent = `function hello() {
197-
console.log("world");
198-
}`;
199-
const searchContent = `function goodbye() {
200-
console.log("world");
201-
}`;
202-
203-
const result = findSearchMatch(fileContent, searchContent);
204-
205-
expect(result?.strategyName).toEqual("jaroWinklerFuzzyMatch");
206-
});
207-
208-
it("should return only fuzzy result when trimmed search content is not found", () => {
209-
const fileContent = `function hello() {
210-
console.log("world");
211-
}`;
212-
const searchContent = `\n\nfunction goodbye() {
213-
console.log("world");
214-
}\n\n`;
215-
216-
const result = findSearchMatch(fileContent, searchContent);
217-
218-
expect(result?.strategyName).toEqual("jaroWinklerFuzzyMatch");
219-
});
220-
});
221-
222194
describe("Edge cases", () => {
223195
it("should handle empty file with non-empty search", () => {
224196
const fileContent = "";
@@ -612,157 +584,4 @@ function test() {
612584
strategyName: "exactMatch",
613585
});
614586
});
615-
616-
describe("Jaro-Winkler fuzzy matching", () => {
617-
describe("Basic fuzzy matching", () => {
618-
it("should find fuzzy match for similar strings", () => {
619-
const fileContent = `function calculateSum(a, b) {
620-
return a + b;
621-
}`;
622-
const searchContent = `function calculateSum(x, y) {
623-
return x + y;
624-
}`;
625-
626-
const result = findSearchMatch(fileContent, searchContent);
627-
628-
expect(result).not.toBeNull();
629-
});
630-
631-
it("should find fuzzy match with minor typos", () => {
632-
const fileContent = `const message = "Hello World";`;
633-
const searchContent = `const mesage = "Hello World";`; // Missing 's' in 'message'
634-
635-
const result = findSearchMatch(fileContent, searchContent);
636-
637-
expect(result).not.toBeNull();
638-
expect(result?.startIndex).toBe(0);
639-
});
640-
641-
it("should find fuzzy match with different variable names", () => {
642-
const fileContent = `let userAge = 25;
643-
let userName = "John";`;
644-
const searchContent = `let age = 25;
645-
let name = "John";`;
646-
647-
const result = findSearchMatch(fileContent, searchContent);
648-
649-
expect(result).not.toBeNull();
650-
});
651-
652-
it("should find fuzzy match for similar function signature", () => {
653-
const fileContent = `function processUserData(userData) {
654-
validateInput(userData);
655-
return formatOutput(userData);
656-
}`;
657-
const searchContent = `function processData(data) {
658-
validateInput(data);
659-
return formatOutput(data);
660-
}`;
661-
662-
const result = findSearchMatch(fileContent, searchContent);
663-
664-
expect(result).not.toBeNull();
665-
});
666-
});
667-
668-
describe("Multi-line fuzzy matching", () => {
669-
it("should find fuzzy match for multi-line blocks", () => {
670-
const fileContent = `class Calculator {
671-
constructor() {
672-
this.result = 0;
673-
}
674-
675-
add(value) {
676-
this.result += value;
677-
return this;
678-
}
679-
}`;
680-
const searchContent = `class Calculator {
681-
constructor() {
682-
this.value = 0;
683-
}
684-
685-
add(num) {
686-
this.value += num;
687-
return this;
688-
}
689-
}`;
690-
691-
const result = findSearchMatch(fileContent, searchContent);
692-
693-
expect(result).not.toBeNull();
694-
});
695-
696-
it("should find fuzzy match for partial blocks", () => {
697-
const fileContent = `function processData(input) {
698-
const validated = validateInput(input);
699-
const processed = transformData(validated);
700-
const result = formatOutput(processed);
701-
return result;
702-
}`;
703-
const searchContent = `const validated = validateInput(input);
704-
const processed = transformData(validated);`;
705-
706-
const result = findSearchMatch(fileContent, searchContent);
707-
708-
expect(result).not.toBeNull();
709-
});
710-
});
711-
712-
describe("Edge cases with fuzzy matching", () => {
713-
it("should handle empty search content with fuzzy matching enabled", () => {
714-
const fileContent = `function test() {}`;
715-
const searchContent = "";
716-
717-
const result = findSearchMatch(fileContent, searchContent);
718-
719-
expect(result).toEqual({
720-
startIndex: 0,
721-
endIndex: 0,
722-
strategyName: "emptySearch",
723-
});
724-
});
725-
726-
it("should handle empty file content with fuzzy matching enabled", () => {
727-
const fileContent = "";
728-
const searchContent = "function test() {}";
729-
730-
const result = findSearchMatch(fileContent, searchContent);
731-
732-
expect(result).toBeNull();
733-
});
734-
735-
it("should prefer exact match over fuzzy match", () => {
736-
const fileContent = `function test() { return true; }
737-
function test() { return false; }`;
738-
const searchContent = `function test() { return true; }`;
739-
740-
const result = findSearchMatch(fileContent, searchContent);
741-
742-
expect(result).not.toBeNull();
743-
expect(result?.startIndex).toBe(0);
744-
});
745-
746-
it("should handle very short strings", () => {
747-
const fileContent = `a b c`;
748-
const searchContent = `a c`;
749-
750-
const result = findSearchMatch(fileContent, searchContent);
751-
752-
// Should not match due to low similarity
753-
expect(result).toBeNull();
754-
});
755-
756-
it("should handle special characters in fuzzy matching", () => {
757-
const fileContent = `const regex = /[a-zA-Z]+/g;
758-
const symbols = !@#$%^&*();`;
759-
const searchContent = `const regex = /[a-zA-Z0-9]+/g;
760-
const symbols = !@#$%^&*();`;
761-
762-
const result = findSearchMatch(fileContent, searchContent);
763-
764-
expect(result).not.toBeNull();
765-
});
766-
});
767-
});
768587
});

0 commit comments

Comments
 (0)