From 2a027c9bb4523f99344a87fca0ca60cc49a05f3c Mon Sep 17 00:00:00 2001 From: EuAndreh Date: Fri, 11 Jul 2025 13:08:04 -0300 Subject: tests/paca.mjs (test_tokenizeRegexStep): Compute `char` and `index` --- tests/paca.mjs | 27 +++++++-------------------- 1 file changed, 7 insertions(+), 20 deletions(-) (limited to 'tests') diff --git a/tests/paca.mjs b/tests/paca.mjs index 7c807fe..0724bf2 100644 --- a/tests/paca.mjs +++ b/tests/paca.mjs @@ -93,10 +93,9 @@ const test_tokenizeRegexStep = t => { t.start("tokenizeRegexStep()"); t.testing("when escaping we get whatever the char is", () => { - const stepFn = tokenizeRegexStep("ab|(cd)*"); + const regex = "ab|(cd)*" + const stepFn = tokenizeRegexStep(regex); const steps = [{ - char: "a", - index: 0, in: { out: [], state: ConcatStep.ESCAPING, @@ -106,8 +105,6 @@ const test_tokenizeRegexStep = t => { state: ConcatStep.ACCEPTING, }, }, { - char: "b", - index: 1, in: { out: [], state: ConcatStep.ESCAPING, @@ -117,8 +114,6 @@ const test_tokenizeRegexStep = t => { state: ConcatStep.ACCEPTING, }, }, { - char: "|", - index: 2, in: { out: [], state: ConcatStep.ESCAPING, @@ -128,8 +123,6 @@ const test_tokenizeRegexStep = t => { state: ConcatStep.ACCEPTING, }, }, { - char: "(", - index: 3, in: { out: [], state: ConcatStep.ESCAPING, @@ -139,19 +132,15 @@ const test_tokenizeRegexStep = t => { state: ConcatStep.ACCEPTING, }, }, { - char: "c", - index: 4, in: { out: [], state: ConcatStep.ESCAPING, }, out: { - out: ["c", {operator: "concat"}], + out: ["c", { operator: "concat" }], state: ConcatStep.ACCEPTING, }, }, { - char: "d", - index: 5, in: { out: [], state: ConcatStep.ESCAPING, @@ -161,8 +150,6 @@ const test_tokenizeRegexStep = t => { state: ConcatStep.ACCEPTING, }, }, { - char: ")", - index: 6, in: { out: [], state: ConcatStep.ESCAPING, @@ -172,8 +159,6 @@ const test_tokenizeRegexStep = t => { state: ConcatStep.ACCEPTING, }, }, { - char: "*", - index: 7, in: { out: [], state: ConcatStep.ESCAPING, @@ -183,9 +168,11 @@ const test_tokenizeRegexStep = t => { state: ConcatStep.ACCEPTING, }, }]; - for (const step of steps) { + for (const i in regex) { + const step = steps[i]; + const char = regex[i]; t.assertEq( - stepFn(step.in, step.char, step.index), + stepFn(step.in, char, Number(i)), step.out, ); } -- cgit v1.2.3