diff options
| author | EuAndreh <eu@euandre.org> | 2025-07-11 15:41:22 -0300 |
|---|---|---|
| committer | EuAndreh <eu@euandre.org> | 2025-07-11 15:41:22 -0300 |
| commit | fc67be3d926d21194fca5e8ff733e0921f6e141c (patch) | |
| tree | 6b67f16d2687ce2e3d5103f21102b6668e22aa6a /tests/paca.mjs | |
| parent | src/paca.mjs (tokenizeRegexStep): Include `context` key in reduced state (diff) | |
| download | paca-fc67be3d926d21194fca5e8ff733e0921f6e141c.tar.gz paca-fc67be3d926d21194fca5e8ff733e0921f6e141c.tar.xz | |
src/paca.mjs (tokenizeRegexStep): Support tokenizing range exps {m,n}
Diffstat (limited to '')
| -rw-r--r-- | tests/paca.mjs | 540 |
1 files changed, 540 insertions, 0 deletions
diff --git a/tests/paca.mjs b/tests/paca.mjs index 82102f1..4f085e4 100644 --- a/tests/paca.mjs +++ b/tests/paca.mjs @@ -353,6 +353,546 @@ const test_tokenizeRegexStep = t => { ); } }); + + t.testing("multichar range operator {m,n} is parsed", () => { + const table = [{ + regex: "a{1,2}", + steps: [{ + in: { + out: [], + state: ConcatStep.ACCEPTING, + context: null, + }, + out: { + out: ["a", { operator: "concat" }], + state: ConcatStep.ACCEPTING, + context: null, + }, + }, { + in: { + out: [], + state: ConcatStep.ACCEPTING, + context: null, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [], + to: [], + where: "from", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [], + to: [], + where: "from", + }, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1" ], + to: [], + where: "from", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1" ], + to: [], + where: "from", + }, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1" ], + to: [], + where: "to", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1" ], + to: [], + where: "to", + }, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1" ], + to: [ "2" ], + where: "to", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1" ], + to: [ "2" ], + where: "to", + }, + }, + out: { + out: [{ + operator: "range", + from: 1, + to: 2, + }], + state: ConcatStep.ACCEPTING, + context: null, + }, + }], + }, { + regex: "a{,2}", + steps: [{ + in: { + out: [], + state: ConcatStep.ACCEPTING, + context: null, + }, + out: { + out: ["a", { operator: "concat" }], + state: ConcatStep.ACCEPTING, + context: null, + }, + }, { + in: { + out: [], + state: ConcatStep.ACCEPTING, + context: null, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [], + to: [], + where: "from", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [], + to: [], + where: "from", + }, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [], + to: [], + where: "to", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [], + to: [], + where: "to", + }, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [], + to: [ "2" ], + where: "to", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [], + to: [ "2" ], + where: "to", + }, + }, + out: { + out: [{ + operator: "range", + from: -1, + to: 2, + }], + state: ConcatStep.ACCEPTING, + context: null, + }, + }], + }, { + regex: "a{1,}", + steps: [{ + in: { + out: [], + state: ConcatStep.ACCEPTING, + context: null, + }, + out: { + out: ["a", { operator: "concat" }], + state: ConcatStep.ACCEPTING, + context: null, + }, + }, { + in: { + out: [], + state: ConcatStep.ACCEPTING, + context: null, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [], + to: [], + where: "from", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [], + to: [], + where: "from", + }, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1" ], + to: [], + where: "from", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1" ], + to: [], + where: "from", + }, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1" ], + to: [], + where: "to", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1" ], + to: [], + where: "to", + }, + }, + out: { + out: [{ + operator: "range", + from: 1, + to: -1, + }], + state: ConcatStep.ACCEPTING, + context: null, + }, + }], + }, { + regex: "a{,}", + steps: [{ + in: { + out: [], + state: ConcatStep.ACCEPTING, + context: null, + }, + out: { + out: ["a", { operator: "concat" }], + state: ConcatStep.ACCEPTING, + context: null, + }, + }, { + in: { + out: [], + state: ConcatStep.ACCEPTING, + context: null, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [], + to: [], + where: "from", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [], + to: [], + where: "from", + }, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [], + to: [], + where: "to", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [], + to: [], + where: "to", + }, + }, + out: { + out: [{ + operator: "range", + from: -1, + to: -1, + }], + state: ConcatStep.ACCEPTING, + context: null, + }, + }], + }, { + regex: "a{123,456}", + steps: [{ + in: { + out: [], + state: ConcatStep.ACCEPTING, + context: null, + }, + out: { + out: ["a", { operator: "concat" }], + state: ConcatStep.ACCEPTING, + context: null, + }, + }, { + in: { + out: [], + state: ConcatStep.ACCEPTING, + context: null, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [], + to: [], + where: "from", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [], + to: [], + where: "from", + }, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1" ], + to: [], + where: "from", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1" ], + to: [], + where: "from", + }, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1", "2" ], + to: [], + where: "from", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1", "2" ], + to: [], + where: "from", + }, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1", "2", "3" ], + to: [], + where: "from", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1", "2", "3" ], + to: [], + where: "from", + }, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1", "2", "3" ], + to: [], + where: "to", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1", "2", "3" ], + to: [], + where: "to", + }, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1", "2", "3" ], + to: [ "4" ], + where: "to", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1", "2", "3" ], + to: [ "4" ], + where: "to", + }, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1", "2", "3" ], + to: [ "4", "5" ], + where: "to", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1", "2", "3" ], + to: [ "4", "5" ], + where: "to", + }, + }, + out: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1", "2", "3" ], + to: [ "4", "5", "6" ], + where: "to", + }, + }, + }, { + in: { + out: [], + state: ConcatStep.RANGE, + context: { + from: [ "1", "2", "3" ], + to: [ "4", "5", "6" ], + where: "to", + }, + }, + out: { + out: [{ + operator: "range", + from: 123, + to: 456, + }], + state: ConcatStep.ACCEPTING, + context: null, + }, + }], + }]; + for (const case_ of table) { + const stepFn = tokenizeRegexStep(case_.regex); + for (const i in case_.regex) { + const step = case_.steps[i]; + const char = case_.regex[i]; + t.assertEq( + stepFn(step.in, char, Number(i)), + step.out, + ); + } + } + }); }; const test_tokenizeRegexFn = t => { |
