summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEuAndreh <eu@euandre.org>2025-07-13 20:29:31 -0300
committerEuAndreh <eu@euandre.org>2025-07-13 20:29:42 -0300
commit3290af93faa50c5c87e5eb7f7dbf0c87c5b934c0 (patch)
tree010d9f07368c303cd4b1ef3b050e783e10b25f88
parentAdd "[" to the possible characters of TRANSITION_FNS. (diff)
downloadpaca-3290af93faa50c5c87e5eb7f7dbf0c87c5b934c0.tar.gz
paca-3290af93faa50c5c87e5eb7f7dbf0c87c5b934c0.tar.xz
Hoist `numFromDigits()` before its usage
* src/paca.mjs (numFromDigits): Move it to before the *StateStep functions, as it is now used in `rangeStateStep()` function. So instead of letting it be defined afters its usage, move it up. * tests/paca.mjs: Do the same hoisting to the import of the `numFromDigits` name, to the definition of `test_numFromDigits` and its inclusion in the order of the call to `runTests()`.
Diffstat (limited to '')
-rw-r--r--src/paca.mjs10
-rw-r--r--tests/paca.mjs34
2 files changed, 22 insertions, 22 deletions
diff --git a/src/paca.mjs b/src/paca.mjs
index 6843c20..c5102c3 100644
--- a/src/paca.mjs
+++ b/src/paca.mjs
@@ -12,6 +12,11 @@ const ConcatStep = {
RANGE: "range",
};
+const numFromDigits = digits =>
+ digits.length === 0
+ ? -1
+ : Number(digits.join(""));
+
const escapingStateStep = ({ out, state, context }, char, index, next) => ({
out: out.concat(
char,
@@ -149,11 +154,6 @@ const shouldConcat = (char, next) =>
const isOperator = char =>
nonConcatOperators.has(char) || char == "(";
-const numFromDigits = digits =>
- digits.length === 0
- ? -1
- : Number(digits.join(""));
-
const tokenizeRegexStep = chars => ({ out, state, context }, char, index) => {
const next = chars[index + 1];
diff --git a/tests/paca.mjs b/tests/paca.mjs
index a7cd929..a4fed28 100644
--- a/tests/paca.mjs
+++ b/tests/paca.mjs
@@ -3,10 +3,10 @@ import { explode, reduced, reductions, runTests } from "sjs";
import {
SyntaxError,
ConcatStep,
+ numFromDigits,
TRANSITION_FNS,
shouldConcat,
isOperator,
- numFromDigits,
tokenizeRegexStep,
tokenizeRegexFn,
tokenizeRegex,
@@ -44,6 +44,21 @@ import {
+const test_numFromDigits = t => {
+ t.start("numFromDigits()");
+
+ t.testing("-1 on empty array", () => {
+ t.assertEq(numFromDigits([]), -1);
+ });
+
+ t.testing("the number from the digits", () => {
+ t.assertEq(numFromDigits([ "0" ]), 0);
+ t.assertEq(numFromDigits([ "1" ]), 1);
+ t.assertEq(numFromDigits([ "0", "1" ]), 1);
+ t.assertEq(numFromDigits([ "1", "2", "3" ]), 123);
+ });
+};
+
const test_TRANSITION_FNS = t => {
t.start("TRANSITION_FNS");
@@ -140,21 +155,6 @@ const test_isOperator = t => {
});
};
-const test_numFromDigits = t => {
- t.start("numFromDigits()");
-
- t.testing("-1 on empty array", () => {
- t.assertEq(numFromDigits([]), -1);
- });
-
- t.testing("the number from the digits", () => {
- t.assertEq(numFromDigits([ "0" ]), 0);
- t.assertEq(numFromDigits([ "1" ]), 1);
- t.assertEq(numFromDigits([ "0", "1" ]), 1);
- t.assertEq(numFromDigits([ "1", "2", "3" ]), 123);
- });
-};
-
const test_tokenizeRegexStep = t => {
t.start("tokenizeRegexStep()");
@@ -2401,10 +2401,10 @@ const test_compile = t => {
runTests([
+ test_numFromDigits,
test_TRANSITION_FNS,
test_shouldConcat,
test_isOperator,
- test_numFromDigits,
test_tokenizeRegexStep,
test_tokenizeRegexFn,
test_tokenizeRegex,