testMerge3
tcmts.cli.merge.testMerge3 · #vpyh35d7 · term
import { merge3 } from "#codebase/tcmts/cli/merge";
export const testMerge3 = () => {
const lines = (s: string) => s.split(" ");
const m = (b: string, o: string, t: string) => merge3(lines(b), lines(o), lines(t))?.join(" ");
// edits in different places combine
if (m("a b c d e", "a B c d e", "a b c D e") !== "a B c D e") throw new Error("both edits");
// one side's edit, and both sides' same edit
if (m("a b c", "a b c", "a X c") !== "a X c") throw new Error("theirs only");
if (m("a b c", "a X c", "a X c") !== "a X c") throw new Error("the same edit");
// additions apart, and a deletion beside an edit elsewhere
if (m("a b c d", "a o b c d", "a b c t d") !== "a o b c t d") throw new Error("additions apart");
if (m("a b c d", "a c d", "a b c D") !== "a c D") throw new Error("a deletion and an edit");
// the same line changed differently, or two additions at one place: a conflict
if (m("a b c", "a O c", "a T c") !== undefined) throw new Error("a conflict");
if (m("a c", "a o c", "a t c") !== undefined) throw new Error("additions at one place");
// a side that changed nothing takes the other's whole
if (m("a", "x y", "a") !== "x y") throw new Error("all of ours");
}
uses