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