Changeset: Add sanity checks to `slicerZipperFunc()`

pull/5268/head
Richard Hansen 2021-03-22 20:23:59 -04:00
parent efeb69b4ea
commit 097f2623c6
1 changed files with 11 additions and 0 deletions

View File

@ -1185,6 +1185,17 @@ const slicerZipperFunc = (attOp, csOp, pool) => {
copyOp(csOp, opOut);
csOp.opcode = '';
} else {
for (const op of [attOp, csOp]) {
assert(op.chars >= op.lines, `op has more newlines than chars: ${op.toString()}`);
}
assert(
attOp.chars < csOp.chars ? attOp.lines <= csOp.lines
: attOp.chars > csOp.chars ? attOp.lines >= csOp.lines
: attOp.lines === csOp.lines,
'line count mismatch when composing changesets A*B; ' +
`opA: ${attOp.toString()} opB: ${csOp.toString()}`);
assert(['+', '='].includes(attOp.opcode), `unexpected opcode in op: ${attOp.toString()}`);
assert(['-', '='].includes(csOp.opcode), `unexpected opcode in op: ${csOp.toString()}`);
opOut.opcode = {
'+': {
'-': '', // The '-' cancels out (some of) the '+', leaving any remainder for the next call.