summaryrefslogtreecommitdiff
path: root/tests/paca.mjs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--tests/paca.mjs98
1 files changed, 98 insertions, 0 deletions
diff --git a/tests/paca.mjs b/tests/paca.mjs
index efee446..82640b1 100644
--- a/tests/paca.mjs
+++ b/tests/paca.mjs
@@ -39,6 +39,8 @@ import {
buildNFAStep,
buildNFA,
allDirects,
+ interpretMetacharacter,
+ performTransition,
searchNFAStep,
searchNFAFn,
searchNFA,
@@ -2675,6 +2677,100 @@ const test_allDirects = t => {
});
};
+const test_interpretMetacharacter = t => {
+ t.start("interpretMetacharacter()");
+
+ t.testing("null on missing meta attribute", () => {
+ t.assertEq(interpretMetacharacter({}, "IGNORED"), null);
+ });
+
+ t.testing("wildcard always matches", () => {
+ const input = {
+ op: true,
+ to: "ret",
+ };
+ t.assertEq(interpretMetacharacter(input, "IGNORED"), "ret");
+ });
+
+ t.testing("matches returns depending on the op", () => {
+ const input1 = {
+ op: "includes",
+ to: "ret",
+ matches: new Set(["a"]),
+ };
+ const input2 = {
+ ...input1,
+ op: "excludes",
+ };
+ t.assertEq(interpretMetacharacter(input1, "a"), "ret");
+ t.assertEq(interpretMetacharacter(input2, "a"), false);
+ });
+
+ t.testing("inRange returns depending on op", () => {
+ const input1 = {
+ op: "includes",
+ to: "ret",
+ matches: new Set([]),
+ ranges: { 97: 122 },
+ };
+ const input2 = {
+ ...input1,
+ op: "excludes",
+ };
+ t.assertEq(interpretMetacharacter(input1, "x"), "ret");
+ t.assertEq(interpretMetacharacter(input2, "x"), false);
+ });
+
+ t.testing("when nothing matches, we look at the op again", () => {
+ const input1 = {
+ op: "includes",
+ to: "ret",
+ matches: new Set([]),
+ ranges: {},
+ };
+ const input2 = {
+ ...input1,
+ op: "excludes",
+ };
+ t.assertEq(interpretMetacharacter(input1, "a"), false);
+ t.assertEq(interpretMetacharacter(input2, "a"), "ret");
+ });
+};
+
+const test_performTransition = t => {
+ t.start("performTransition()");
+
+ t.testing("either get the direct transition", () => {
+ const nodes = {
+ 1: {
+ transitions: { a: 2 },
+ },
+ 2: {
+ transitions: {},
+ },
+ };
+ t.assertEq(performTransition(nodes, "a")(1), 2);
+ t.assertEq(performTransition(nodes, "a")(2), null);
+ });
+
+ t.testing("or execute the meta attribute", () => {
+ const nodes = {
+ 1: {
+ transitions: {},
+ meta: {
+ op: true,
+ to: 2,
+ },
+ },
+ 2: {
+ transitions: {},
+ },
+ };
+ t.assertEq(performTransition(nodes, "a")(1), 2);
+ t.assertEq(performTransition(nodes, "a")(2), null);
+ });
+};
+
const test_searchNFAStep = t => {
t.start("searchNFAStep()");
@@ -3459,6 +3555,8 @@ runTests([
test_buildNFAStep,
test_buildNFA,
test_allDirects,
+ test_interpretMetacharacter,
+ test_performTransition,
test_searchNFAStep,
test_searchNFAFn,
test_searchNFA,