Changeset: Use string templates

Co-authored-by: Richard Hansen <rhansen@rhansen.org>
pull/5269/head
webzwo0i 2021-10-17 20:33:53 +02:00
parent cb95e5907c
commit 8b73b911c9
1 changed files with 10 additions and 12 deletions

View File

@ -46,13 +46,11 @@ exports.error = (msg) => {
* throw an exception. * throw an exception.
* *
* @param {boolean} b - assertion condition * @param {boolean} b - assertion condition
* @param {...any} msgParts - error message to include in the exception * @param {string} msg - error message to include in the exception
* @type {(b: boolean, ...msgParts: any[]) => asserts b} * @type {(b: boolean, msg: string) => asserts b}
*/ */
exports.assert = (b, ...msgParts) => { exports.assert = (b, msg) => {
if (!b) { if (!b) exports.error(`Failed assertion: ${msg}`);
exports.error(`Failed assertion: ${msgParts.join('')}`);
}
}; };
/** /**
@ -282,13 +280,13 @@ exports.checkRep = (cs) => {
break; break;
case '-': case '-':
oldPos += o.chars; oldPos += o.chars;
exports.assert(oldPos <= oldLen, oldPos, ' > ', oldLen, ' in ', cs); exports.assert(oldPos <= oldLen, `${oldPos} > ${oldLen} in ${cs}`);
break; break;
case '+': case '+':
{ {
calcNewLen += o.chars; calcNewLen += o.chars;
numInserted += o.chars; numInserted += o.chars;
exports.assert(calcNewLen <= newLen, calcNewLen, ' > ', newLen, ' in ', cs); exports.assert(calcNewLen <= newLen, `${calcNewLen} > ${newLen} in ${cs}`);
break; break;
} }
} }
@ -538,7 +536,7 @@ exports.stringIterator = (str) => {
const getnewLines = () => newLines; const getnewLines = () => newLines;
const assertRemaining = (n) => { const assertRemaining = (n) => {
exports.assert(n <= remaining(), '!(', n, ' <= ', remaining(), ')'); exports.assert(n <= remaining(), `!(${n} <= ${remaining()})`);
}; };
const take = (n) => { const take = (n) => {
@ -1066,8 +1064,8 @@ exports.pack = (oldLen, newLen, opsStr, bank) => {
*/ */
exports.applyToText = (cs, str) => { exports.applyToText = (cs, str) => {
const unpacked = exports.unpack(cs); const unpacked = exports.unpack(cs);
exports.assert(str.length === unpacked.oldLen, 'mismatched apply: ', str.length, exports.assert(
' / ', unpacked.oldLen); str.length === unpacked.oldLen, `mismatched apply: ${str.length} / ${unpacked.oldLen}`);
const csIter = exports.opIterator(unpacked.ops); const csIter = exports.opIterator(unpacked.ops);
const bankIter = exports.stringIterator(unpacked.charBank); const bankIter = exports.stringIterator(unpacked.charBank);
const strIter = exports.stringIterator(str); const strIter = exports.stringIterator(str);
@ -1338,7 +1336,7 @@ exports.mutateAttributionLines = (cs, lines, pool) => {
} }
lineAssem.append(op); lineAssem.append(op);
if (op.lines > 0) { if (op.lines > 0) {
exports.assert(op.lines === 1, "Can't have op.lines of ", op.lines, ' in attribution lines'); exports.assert(op.lines === 1, `Can't have op.lines of ${op.lines} in attribution lines`);
// ship it to the mut // ship it to the mut
mut.insert(lineAssem.toString(), 1); mut.insert(lineAssem.toString(), 1);
lineAssem = null; lineAssem = null;