diff options
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 => { |
