Fix ranges/union()
This commit is contained in:
parent
6820f88bd6
commit
9986cfb35c
4 changed files with 29 additions and 13 deletions
|
|
@ -19,6 +19,14 @@ describe("Test myers diff function", () => {
|
|||
E
|
||||
`;
|
||||
const diffLines = myersDiff(linesA, linesB);
|
||||
console.log(diffLines);
|
||||
expect(diffLines).toEqual([
|
||||
{ type: "same", line: "A" },
|
||||
{ type: "same", line: "B" },
|
||||
{ type: "old", line: "C" },
|
||||
{ type: "old", line: "D" },
|
||||
{ type: "new", line: "C'" },
|
||||
{ type: "new", line: "D'" },
|
||||
{ type: "same", line: "E" },
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
|
|
@ -137,7 +137,6 @@ describe("CodebaseIndexer", () => {
|
|||
del: number,
|
||||
) {
|
||||
const plan = await getIndexPlan();
|
||||
console.log("PLAN: ", plan);
|
||||
expect(plan.compute).toHaveLength(compute);
|
||||
expect(plan.addTag).toHaveLength(addTag);
|
||||
expect(plan.removeTag).toHaveLength(removeTag);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
// This file is generated by Continue
|
||||
|
||||
import {
|
||||
intersection,
|
||||
getRangeInString,
|
||||
intersection,
|
||||
maxPosition,
|
||||
minPosition,
|
||||
union,
|
||||
|
|
@ -80,8 +80,7 @@ describe("union", () => {
|
|||
});
|
||||
});
|
||||
|
||||
// TODO
|
||||
test.skip("should handle edge case where start and end lines are the same", () => {
|
||||
test("should handle edge case where start and end lines are the same", () => {
|
||||
rangeA = {
|
||||
start: { line: 1, character: 0 },
|
||||
end: { line: 1, character: 5 },
|
||||
|
|
|
|||
|
|
@ -58,17 +58,27 @@ export function intersection(a: Range, b: Range): Range | null {
|
|||
}
|
||||
|
||||
export function union(a: Range, b: Range): Range {
|
||||
const startLine = Math.min(a.start.line, b.start.line);
|
||||
const endLine = Math.max(a.end.line, b.end.line);
|
||||
let start: Position;
|
||||
if (a.start.line === b.start.line) {
|
||||
start = {
|
||||
line: a.start.line,
|
||||
character: Math.min(a.start.character, b.start.character),
|
||||
};
|
||||
} else if (a.start.line < b.start.line) start = a.start;
|
||||
else start = b.start;
|
||||
|
||||
const startCharacter =
|
||||
startLine === a.start.line ? a.start.character : b.start.character;
|
||||
const endCharacter =
|
||||
endLine === a.end.line ? a.end.character : b.end.character;
|
||||
let end: Position;
|
||||
if (a.end.line === b.end.line) {
|
||||
end = {
|
||||
line: a.end.line,
|
||||
character: Math.max(a.end.character, b.end.character),
|
||||
};
|
||||
} else if (a.end.line > b.end.line) end = a.end;
|
||||
else end = b.end;
|
||||
|
||||
return {
|
||||
start: { line: startLine, character: startCharacter },
|
||||
end: { line: endLine, character: endCharacter },
|
||||
start,
|
||||
end,
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue