| 25103ddd Andy McCall ↶ |
1 |
import { test } from "node:test"; |
| 2 |
import assert from "node:assert/strict"; |
| 3 |
import { parseConflicts, resolveRegion, candidateBase } from "../out/markers.mjs"; |
| 4 |
|
| 5 |
test("parses order conflicts with several sides", () => { |
| 6 |
const lines = [ |
| 7 |
"a", |
| 8 |
'<<<<<<< oxy conflict 1 of 2, side 1 of 3: change 872724ae "Doing"', |
| 9 |
"How are you doing?", |
| 10 |
'======= oxy conflict 1 of 2, side 2 of 3: change 194a1869 "Today"', |
| 11 |
"How are you today?", |
| 12 |
'======= oxy conflict 1 of 2, side 3 of 3: change 55555555 "Third"', |
| 13 |
"third", |
| 14 |
"more third", |
| 15 |
">>>>>>> oxy conflict 1 of 2 end", |
| 16 |
"z", |
| 17 |
]; |
| 18 |
const regions = parseConflicts(lines); |
| 19 |
assert.equal(regions.length, 1); |
| 20 |
const r = regions[0]; |
| 21 |
assert.deepEqual([r.number, r.total, r.start, r.end], [1, 2, 1, 8]); |
| 22 |
assert.deepEqual(r.sides.map((s) => [s.number, s.label, s.start, s.end]), [ |
| 23 |
[1, '872724ae "Doing"', 2, 3], |
| 24 |
[2, '194a1869 "Today"', 4, 5], |
| 25 |
[3, '55555555 "Third"', 6, 8], |
| 26 |
]); |
| 27 |
assert.deepEqual(resolveRegion(lines, r, [2]), ["How are you today?"]); |
| 28 |
assert.deepEqual(resolveRegion(lines, r, [1, 3]), ["How are you doing?", "third", "more third"]); |
| 29 |
}); |
| 30 |
|
| 31 |
test("parses delete versus insert conflicts", () => { |
| 32 |
const lines = [ |
| 33 |
"<<<<<<< oxy conflict 1 of 1, side 1 of 2: deleted by change 0101", |
| 34 |
"-------", |
| 35 |
"a", |
| 36 |
"======= oxy conflict 1 of 1, side 2 of 2: change 0202", |
| 37 |
"after-a", |
| 38 |
">>>>>>> oxy conflict 1 of 1 end", |
| 39 |
]; |
| 40 |
const [r] = parseConflicts(lines); |
| 41 |
assert.equal(r.sides[0].deleted, true); |
| 42 |
assert.deepEqual([r.sides[0].start, r.sides[0].end], [2, 3]); |
| 43 |
assert.deepEqual(resolveRegion(lines, r, [1]), [], "accepting the deletion keeps nothing"); |
| 44 |
assert.deepEqual(resolveRegion(lines, r, [2]), ["after-a"]); |
| 45 |
assert.deepEqual(parseConflicts(["plain", "text"]), []); |
| 46 |
}); |
| 47 |
|
| 48 |
test("candidate names", () => { |
| 49 |
assert.equal(candidateBase("dir/a.txt.oxy-conflict-2"), "dir/a.txt"); |
| 50 |
assert.equal(candidateBase("a.txt"), undefined); |
| 51 |
}); |