fix smart conflict
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { deepStrictEqual, rejects, throws } from "assert";
|
||||
import { getFileRenameForDup } from "../src/conflictLogic";
|
||||
import {
|
||||
getFileRenameForDup,
|
||||
threeWayMerge,
|
||||
twoWayMerge,
|
||||
} from "../src/conflictLogic";
|
||||
|
||||
describe("New name is generated", () => {
|
||||
it("should throw for empty file", async () => {
|
||||
@@ -69,3 +73,224 @@ describe("New name is generated", () => {
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Two way merge", () => {
|
||||
it("should correctly merge from zero files", async () => {
|
||||
const a = "aaa";
|
||||
const b = "bbb";
|
||||
const res = twoWayMerge(a, b);
|
||||
const expected = `\`<<<<<<<\`
|
||||
aaa
|
||||
\`=======\`
|
||||
bbb
|
||||
\`>>>>>>>\``;
|
||||
deepStrictEqual(expected, res);
|
||||
});
|
||||
|
||||
it("should correctly merge from common lines", async () => {
|
||||
const a = `
|
||||
Something is cool. 中文1
|
||||
Other thing is cooler. 哈哈!
|
||||
`;
|
||||
const b = `
|
||||
Anything is cool. 中文2
|
||||
Other thing is cooler. 哈哈!
|
||||
`;
|
||||
const res = twoWayMerge(a, b);
|
||||
// console.log(res);
|
||||
const expected = `
|
||||
\`<<<<<<<\`
|
||||
Something is cool. 中文1
|
||||
\`=======\`
|
||||
Anything is cool. 中文2
|
||||
\`>>>>>>>\`
|
||||
Other thing is cooler. 哈哈!
|
||||
`;
|
||||
deepStrictEqual(expected, res);
|
||||
});
|
||||
|
||||
it("should merge by lines", async () => {
|
||||
const a = `
|
||||
Something is cool. 中文1
|
||||
`;
|
||||
const b = `
|
||||
Something is cooler. 中文2
|
||||
`;
|
||||
const res = twoWayMerge(a, b);
|
||||
// console.log(res);
|
||||
const expected = `
|
||||
\`<<<<<<<\`
|
||||
Something is cool. 中文1
|
||||
\`=======\`
|
||||
Something is cooler. 中文2
|
||||
\`>>>>>>>\`
|
||||
`;
|
||||
deepStrictEqual(expected, res);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Three way merge", () => {
|
||||
it("should correctly merge from zero files", async () => {
|
||||
const orig = "";
|
||||
const a = "aaa";
|
||||
const b = "bbb";
|
||||
const res = threeWayMerge(a, b, orig);
|
||||
const expected = `\`<<<<<<<\`
|
||||
aaa
|
||||
\`=======\`
|
||||
bbb
|
||||
\`>>>>>>>\``;
|
||||
deepStrictEqual(expected, res);
|
||||
});
|
||||
|
||||
it("should correctly merge after adding lines on both sides", async () => {
|
||||
const orig = `
|
||||
* [ ] A1
|
||||
* [ ] A2
|
||||
* [ ] A3
|
||||
`;
|
||||
const a = `
|
||||
* [ ] A1
|
||||
* [ ] new line after A1
|
||||
* [ ] A2
|
||||
* [ ] A3
|
||||
`;
|
||||
const b = `
|
||||
* [ ] A1
|
||||
* [ ] A2
|
||||
* [ ] New line after A2
|
||||
* [ ] A3
|
||||
`;
|
||||
const res = threeWayMerge(a, b, orig);
|
||||
// console.log(res);
|
||||
const expected = `
|
||||
* [ ] A1
|
||||
* [ ] new line after A1
|
||||
* [ ] A2
|
||||
* [ ] New line after A2
|
||||
* [ ] A3
|
||||
`;
|
||||
deepStrictEqual(expected, res);
|
||||
});
|
||||
|
||||
it("should correctly merge after adding lines on both sides (again)", async () => {
|
||||
const orig = `
|
||||
* [ ] 中文
|
||||
* [ ] にほんご/にっぽんご
|
||||
* [ ] A3
|
||||
`;
|
||||
const a = `
|
||||
* [ ] 中文
|
||||
* [ ] new line after 中文
|
||||
* [ ] にほんご/にっぽんご
|
||||
* [ ] A3
|
||||
`;
|
||||
const b = `
|
||||
* [ ] 中文
|
||||
* [ ] にほんご/にっぽんご
|
||||
* [ ] New line after にほんご/にっぽんご
|
||||
* [ ] A3
|
||||
`;
|
||||
const res = threeWayMerge(a, b, orig);
|
||||
// console.log(res);
|
||||
const expected = `
|
||||
* [ ] 中文
|
||||
* [ ] new line after 中文
|
||||
* [ ] にほんご/にっぽんご
|
||||
* [ ] New line after にほんご/にっぽんご
|
||||
* [ ] A3
|
||||
`;
|
||||
deepStrictEqual(expected, res);
|
||||
});
|
||||
|
||||
it("should correctly merge after deleting lines on both sides", async () => {
|
||||
const orig = `
|
||||
* [ ] 中文
|
||||
* [ ] にほんご/にっぽんご
|
||||
* [ ] A3
|
||||
* [ ] A4
|
||||
`;
|
||||
const a = `
|
||||
* [ ] にほんご/にっぽんご
|
||||
* [ ] A3
|
||||
* [ ] A4
|
||||
`;
|
||||
const b = `
|
||||
* [ ] 中文
|
||||
* [ ] A3
|
||||
* [ ] A4
|
||||
`;
|
||||
const res = threeWayMerge(a, b, orig);
|
||||
// console.log(res);
|
||||
const expected = `
|
||||
\`<<<<<<<\`
|
||||
* [ ] にほんご/にっぽんご
|
||||
\`=======\`
|
||||
* [ ] 中文
|
||||
\`>>>>>>>\`
|
||||
* [ ] A3
|
||||
* [ ] A4
|
||||
`;
|
||||
deepStrictEqual(expected, res);
|
||||
});
|
||||
|
||||
it("should correctly merge after adding on one side and deleting on other side", async () => {
|
||||
const orig = `
|
||||
* [ ] 中文
|
||||
* [ ] A3
|
||||
* [ ] A4
|
||||
`;
|
||||
const a = `
|
||||
* [ ] 中文
|
||||
* [ ] にほんご/にっぽんご
|
||||
* [ ] A3
|
||||
* [ ] A4
|
||||
`;
|
||||
const b = `
|
||||
* [ ] A3
|
||||
* [ ] A4
|
||||
`;
|
||||
const res = threeWayMerge(a, b, orig);
|
||||
// console.log(res);
|
||||
const expected = `
|
||||
\`<<<<<<<\`
|
||||
* [ ] 中文
|
||||
* [ ] にほんご/にっぽんご
|
||||
\`=======\`
|
||||
\`>>>>>>>\`
|
||||
* [ ] A3
|
||||
* [ ] A4
|
||||
`;
|
||||
deepStrictEqual(expected, res);
|
||||
});
|
||||
|
||||
it("should correctly merge after adding on one side and deleting on other side (again)", async () => {
|
||||
const orig = `
|
||||
* [ ] 中文
|
||||
* [ ] A3
|
||||
* [ ] A4
|
||||
`;
|
||||
const a = `
|
||||
* [ ] A3
|
||||
* [ ] A4
|
||||
`;
|
||||
const b = `
|
||||
* [ ] 中文
|
||||
* [ ] にほんご/にっぽんご
|
||||
* [ ] A3
|
||||
* [ ] A4
|
||||
`;
|
||||
const res = threeWayMerge(a, b, orig);
|
||||
// console.log(res);
|
||||
const expected = `
|
||||
\`<<<<<<<\`
|
||||
\`=======\`
|
||||
* [ ] 中文
|
||||
* [ ] にほんご/にっぽんご
|
||||
\`>>>>>>>\`
|
||||
* [ ] A3
|
||||
* [ ] A4
|
||||
`;
|
||||
deepStrictEqual(expected, res);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user