yukigo 0.2.3 → 0.3.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.mocharc.json +3 -3
- package/CHANGELOG.md +105 -40
- package/README.md +193 -193
- package/dist/analyzer/GraphBuilder.d.ts +1 -0
- package/dist/analyzer/GraphBuilder.js +2 -1
- package/dist/analyzer/index.d.ts +0 -7
- package/dist/analyzer/index.js +3 -3
- package/dist/analyzer/inspections/functional/functional.d.ts +1 -1
- package/dist/analyzer/inspections/functional/functional.js +1 -1
- package/dist/analyzer/inspections/functional/smells.d.ts +3 -3
- package/dist/analyzer/inspections/functional/smells.js +27 -35
- package/dist/analyzer/inspections/generic/generic.d.ts +22 -14
- package/dist/analyzer/inspections/generic/generic.js +82 -60
- package/dist/analyzer/inspections/generic/smells.d.ts +2 -0
- package/dist/analyzer/inspections/generic/smells.js +55 -64
- package/dist/analyzer/inspections/imperative/imperative.d.ts +3 -3
- package/dist/analyzer/inspections/imperative/imperative.js +3 -3
- package/dist/analyzer/inspections/imperative/smells.d.ts +1 -0
- package/dist/analyzer/inspections/imperative/smells.js +8 -5
- package/dist/analyzer/inspections/logic/logic.d.ts +8 -8
- package/dist/analyzer/inspections/logic/logic.js +5 -5
- package/dist/analyzer/inspections/logic/smells.js +2 -2
- package/dist/analyzer/inspections/object/object.d.ts +5 -5
- package/dist/analyzer/inspections/object/object.js +22 -21
- package/dist/analyzer/inspections/object/smells.js +11 -23
- package/dist/analyzer/utils.d.ts +6 -2
- package/dist/analyzer/utils.js +6 -2
- package/dist/interpreter/components/EnvBuilder.d.ts +20 -1
- package/dist/interpreter/components/EnvBuilder.js +211 -66
- package/dist/interpreter/components/EqualityComparer.d.ts +15 -0
- package/dist/interpreter/components/EqualityComparer.js +69 -0
- package/dist/interpreter/components/Operations.d.ts +17 -14
- package/dist/interpreter/components/Operations.js +61 -62
- package/dist/interpreter/components/PatternMatcher.d.ts +19 -58
- package/dist/interpreter/components/PatternMatcher.js +185 -286
- package/dist/interpreter/components/RuntimeContext.d.ts +24 -15
- package/dist/interpreter/components/RuntimeContext.js +43 -4
- package/dist/interpreter/components/TestRunner.d.ts +15 -13
- package/dist/interpreter/components/TestRunner.js +86 -53
- package/dist/interpreter/components/evaluators/BaseEvaluator.d.ts +19 -0
- package/dist/interpreter/components/evaluators/BaseEvaluator.js +20 -0
- package/dist/interpreter/components/evaluators/ExpressionEvaluator.d.ts +34 -0
- package/dist/interpreter/components/evaluators/ExpressionEvaluator.js +298 -0
- package/dist/interpreter/components/evaluators/OperationEvaluator.d.ts +25 -0
- package/dist/interpreter/components/evaluators/OperationEvaluator.js +226 -0
- package/dist/interpreter/components/evaluators/PrimitiveEvaluator.d.ts +19 -0
- package/dist/interpreter/components/evaluators/PrimitiveEvaluator.js +50 -0
- package/dist/interpreter/components/evaluators/StatementEvaluator.d.ts +28 -0
- package/dist/interpreter/components/evaluators/StatementEvaluator.js +240 -0
- package/dist/interpreter/components/evaluators/TestingEvaluator.d.ts +15 -0
- package/dist/interpreter/components/evaluators/TestingEvaluator.js +14 -0
- package/dist/interpreter/components/evaluators/index.d.ts +110 -0
- package/dist/interpreter/components/evaluators/index.js +21 -0
- package/dist/interpreter/components/evaluators/utils.d.ts +7 -0
- package/dist/interpreter/components/evaluators/utils.js +50 -0
- package/dist/interpreter/components/hooks/YukigoHook.d.ts +27 -0
- package/dist/interpreter/components/hooks/YukigoHook.js +1 -0
- package/dist/interpreter/components/kernel/commands.d.ts +122 -0
- package/dist/interpreter/components/kernel/commands.js +203 -0
- package/dist/interpreter/components/kernel/index.d.ts +51 -0
- package/dist/interpreter/components/kernel/index.js +176 -0
- package/dist/interpreter/components/logic/LogicEngine.d.ts +26 -23
- package/dist/interpreter/components/logic/LogicEngine.js +234 -221
- package/dist/interpreter/components/logic/LogicResolver.d.ts +22 -51
- package/dist/interpreter/components/logic/LogicResolver.js +73 -440
- package/dist/interpreter/components/logic/LogicTerm.d.ts +104 -0
- package/dist/interpreter/components/logic/LogicTerm.js +423 -0
- package/dist/interpreter/components/logic/LogicTranslator.d.ts +25 -9
- package/dist/interpreter/components/logic/LogicTranslator.js +211 -74
- package/dist/interpreter/components/runtimes/FunctionRuntime.d.ts +6 -4
- package/dist/interpreter/components/runtimes/FunctionRuntime.js +82 -84
- package/dist/interpreter/components/runtimes/LazyRuntime.d.ts +13 -14
- package/dist/interpreter/components/runtimes/LazyRuntime.js +112 -239
- package/dist/interpreter/components/runtimes/ObjectRuntime.d.ts +17 -14
- package/dist/interpreter/components/runtimes/ObjectRuntime.js +105 -74
- package/dist/interpreter/errors.d.ts +10 -0
- package/dist/interpreter/errors.js +17 -0
- package/dist/interpreter/index.d.ts +9 -5
- package/dist/interpreter/index.js +11 -13
- package/dist/interpreter/primitives/YuValue.d.ts +21 -0
- package/dist/interpreter/primitives/YuValue.js +40 -0
- package/dist/interpreter/primitives/capabilities.d.ts +90 -0
- package/dist/interpreter/primitives/capabilities.js +1 -0
- package/dist/interpreter/primitives/entities/LazyList.d.ts +48 -0
- package/dist/interpreter/primitives/entities/LazyList.js +164 -0
- package/dist/interpreter/primitives/entities/LogicResult.d.ts +51 -0
- package/dist/interpreter/primitives/entities/LogicResult.js +101 -0
- package/dist/interpreter/primitives/entities/RuntimeClass.d.ts +24 -0
- package/dist/interpreter/primitives/entities/RuntimeClass.js +57 -0
- package/dist/interpreter/primitives/entities/RuntimeFunction.d.ts +40 -0
- package/dist/interpreter/primitives/entities/RuntimeFunction.js +73 -0
- package/dist/interpreter/primitives/entities/RuntimeObject.d.ts +27 -0
- package/dist/interpreter/primitives/entities/RuntimeObject.js +82 -0
- package/dist/interpreter/primitives/entities/RuntimePredicate.d.ts +19 -0
- package/dist/interpreter/primitives/entities/RuntimePredicate.js +59 -0
- package/dist/interpreter/primitives/index.d.ts +14 -0
- package/dist/interpreter/primitives/index.js +14 -0
- package/dist/interpreter/primitives/scalars/YuBoolean.d.ts +24 -0
- package/dist/interpreter/primitives/scalars/YuBoolean.js +69 -0
- package/dist/interpreter/primitives/scalars/YuChar.d.ts +28 -0
- package/dist/interpreter/primitives/scalars/YuChar.js +78 -0
- package/dist/interpreter/primitives/scalars/YuNil.d.ts +25 -0
- package/dist/interpreter/primitives/scalars/YuNil.js +73 -0
- package/dist/interpreter/primitives/scalars/YuNumber.d.ts +49 -0
- package/dist/interpreter/primitives/scalars/YuNumber.js +165 -0
- package/dist/interpreter/primitives/sequences/YuArray.d.ts +33 -0
- package/dist/interpreter/primitives/sequences/YuArray.js +150 -0
- package/dist/interpreter/primitives/sequences/YuString.d.ts +40 -0
- package/dist/interpreter/primitives/sequences/YuString.js +130 -0
- package/dist/interpreter/utils.d.ts +23 -10
- package/dist/interpreter/utils.js +25 -30
- package/dist/tester/index.d.ts +3 -3
- package/dist/tester/index.js +39 -28
- package/dist/utils/helpers.d.ts +13 -5
- package/dist/utils/helpers.js +38 -85
- package/package.json +3 -16
- package/src/analyzer/GraphBuilder.ts +143 -142
- package/src/analyzer/index.ts +185 -194
- package/src/analyzer/inspections/functional/functional.ts +121 -121
- package/src/analyzer/inspections/functional/smells.ts +88 -102
- package/src/analyzer/inspections/generic/generic.ts +610 -577
- package/src/analyzer/inspections/generic/smells.ts +355 -365
- package/src/analyzer/inspections/imperative/imperative.ts +104 -101
- package/src/analyzer/inspections/imperative/smells.ts +58 -54
- package/src/analyzer/inspections/logic/logic.ts +84 -90
- package/src/analyzer/inspections/logic/smells.ts +54 -54
- package/src/analyzer/inspections/object/object.ts +295 -264
- package/src/analyzer/inspections/object/smells.ts +130 -144
- package/src/analyzer/utils.ts +115 -109
- package/src/index.ts +3 -3
- package/src/interpreter/components/EnvBuilder.ts +405 -202
- package/src/interpreter/components/EqualityComparer.ts +107 -0
- package/src/interpreter/components/Operations.ts +126 -99
- package/src/interpreter/components/PatternMatcher.ts +375 -475
- package/src/interpreter/components/RuntimeContext.ts +181 -119
- package/src/interpreter/components/TestRunner.ts +223 -151
- package/src/interpreter/components/evaluators/BaseEvaluator.ts +36 -0
- package/src/interpreter/components/evaluators/ExpressionEvaluator.ts +475 -0
- package/src/interpreter/components/evaluators/OperationEvaluator.ts +477 -0
- package/src/interpreter/components/evaluators/PrimitiveEvaluator.ts +80 -0
- package/src/interpreter/components/evaluators/StatementEvaluator.ts +372 -0
- package/src/interpreter/components/evaluators/TestingEvaluator.ts +26 -0
- package/src/interpreter/components/evaluators/index.ts +34 -0
- package/src/interpreter/components/evaluators/utils.ts +64 -0
- package/src/interpreter/components/hooks/YukigoHook.ts +45 -0
- package/src/interpreter/components/kernel/commands.ts +255 -0
- package/src/interpreter/components/kernel/index.ts +222 -0
- package/src/interpreter/components/logic/LogicEngine.ts +509 -519
- package/src/interpreter/components/logic/LogicResolver.ts +209 -858
- package/src/interpreter/components/logic/LogicTerm.ts +477 -0
- package/src/interpreter/components/logic/LogicTranslator.ts +362 -149
- package/src/interpreter/components/runtimes/FunctionRuntime.ts +249 -227
- package/src/interpreter/components/runtimes/LazyRuntime.ts +226 -334
- package/src/interpreter/components/runtimes/ObjectRuntime.ts +262 -224
- package/src/interpreter/errors.ts +68 -47
- package/src/interpreter/index.ts +50 -52
- package/src/interpreter/primitives/YuValue.ts +64 -0
- package/src/interpreter/primitives/capabilities.ts +111 -0
- package/src/interpreter/primitives/entities/LazyList.ts +225 -0
- package/src/interpreter/primitives/entities/LogicResult.ts +133 -0
- package/src/interpreter/primitives/entities/RuntimeClass.ts +70 -0
- package/src/interpreter/primitives/entities/RuntimeFunction.ts +108 -0
- package/src/interpreter/primitives/entities/RuntimeObject.ts +110 -0
- package/src/interpreter/primitives/entities/RuntimePredicate.ts +77 -0
- package/src/interpreter/primitives/index.ts +17 -0
- package/src/interpreter/primitives/scalars/YuBoolean.ts +79 -0
- package/src/interpreter/primitives/scalars/YuChar.ts +94 -0
- package/src/interpreter/primitives/scalars/YuNil.ts +84 -0
- package/src/interpreter/primitives/scalars/YuNumber.ts +187 -0
- package/src/interpreter/primitives/sequences/YuArray.ts +178 -0
- package/src/interpreter/primitives/sequences/YuString.ts +165 -0
- package/src/interpreter/utils.ts +105 -84
- package/src/tester/index.ts +157 -128
- package/src/utils/helpers.ts +113 -169
- package/tests/analyzer/functional.spec.ts +221 -207
- package/tests/analyzer/generic.spec.ts +178 -178
- package/tests/analyzer/helpers.spec.ts +83 -89
- package/tests/analyzer/logic.spec.ts +237 -237
- package/tests/analyzer/oop.spec.ts +320 -323
- package/tests/analyzer/transitive.spec.ts +166 -166
- package/tests/interpreter/EnvBuilder.spec.ts +181 -183
- package/tests/interpreter/FunctionRuntime.spec.ts +224 -223
- package/tests/interpreter/LazyRuntime.spec.ts +227 -225
- package/tests/interpreter/LogicEngine.spec.ts +371 -327
- package/tests/interpreter/LogicSubstitution.spec.ts +90 -80
- package/tests/interpreter/ObjectRuntime.spec.ts +431 -606
- package/tests/interpreter/Operations.spec.ts +312 -220
- package/tests/interpreter/PatternSystem.spec.ts +254 -213
- package/tests/interpreter/Tests.spec.ts +122 -122
- package/tests/interpreter/interpreter.spec.ts +1143 -991
- package/tests/kernel/YukigoKernel.spec.ts +112 -0
- package/tests/tester/Tester.spec.ts +156 -152
- package/tsconfig.build.json +16 -15
- package/tsconfig.json +27 -25
- package/dist/interpreter/components/Visitor.d.ts +0 -70
- package/dist/interpreter/components/Visitor.js +0 -634
- package/dist/interpreter/entities.d.ts +0 -105
- package/dist/interpreter/entities.js +0 -96
- package/dist/interpreter/trampoline.d.ts +0 -17
- package/dist/interpreter/trampoline.js +0 -38
- package/dist/src/analyzer/GraphBuilder.d.ts +0 -30
- package/dist/src/analyzer/GraphBuilder.js +0 -100
- package/dist/src/analyzer/index.d.ts +0 -59
- package/dist/src/analyzer/index.js +0 -152
- package/dist/src/analyzer/inspections/functional/functional.d.ts +0 -44
- package/dist/src/analyzer/inspections/functional/functional.js +0 -149
- package/dist/src/analyzer/inspections/functional/smells.d.ts +0 -16
- package/dist/src/analyzer/inspections/functional/smells.js +0 -98
- package/dist/src/analyzer/inspections/generic/generic.d.ts +0 -178
- package/dist/src/analyzer/inspections/generic/generic.js +0 -604
- package/dist/src/analyzer/inspections/generic/smells.d.ts +0 -61
- package/dist/src/analyzer/inspections/generic/smells.js +0 -349
- package/dist/src/analyzer/inspections/imperative/imperative.d.ts +0 -35
- package/dist/src/analyzer/inspections/imperative/imperative.js +0 -109
- package/dist/src/analyzer/inspections/imperative/smells.d.ts +0 -16
- package/dist/src/analyzer/inspections/imperative/smells.js +0 -58
- package/dist/src/analyzer/inspections/logic/logic.d.ts +0 -32
- package/dist/src/analyzer/inspections/logic/logic.js +0 -96
- package/dist/src/analyzer/inspections/logic/smells.d.ts +0 -15
- package/dist/src/analyzer/inspections/logic/smells.js +0 -60
- package/dist/src/analyzer/inspections/object/object.d.ts +0 -90
- package/dist/src/analyzer/inspections/object/object.js +0 -321
- package/dist/src/analyzer/inspections/object/smells.d.ts +0 -30
- package/dist/src/analyzer/inspections/object/smells.js +0 -135
- package/dist/src/analyzer/utils.d.ts +0 -30
- package/dist/src/analyzer/utils.js +0 -78
- package/dist/src/index.d.ts +0 -4
- package/dist/src/index.js +0 -4
- package/dist/src/interpreter/components/EnvBuilder.d.ts +0 -21
- package/dist/src/interpreter/components/EnvBuilder.js +0 -155
- package/dist/src/interpreter/components/Operations.d.ts +0 -14
- package/dist/src/interpreter/components/Operations.js +0 -84
- package/dist/src/interpreter/components/PatternMatcher.d.ts +0 -73
- package/dist/src/interpreter/components/PatternMatcher.js +0 -358
- package/dist/src/interpreter/components/RuntimeContext.d.ts +0 -35
- package/dist/src/interpreter/components/RuntimeContext.js +0 -93
- package/dist/src/interpreter/components/TestRunner.d.ts +0 -19
- package/dist/src/interpreter/components/TestRunner.js +0 -110
- package/dist/src/interpreter/components/Visitor.d.ts +0 -71
- package/dist/src/interpreter/components/Visitor.js +0 -638
- package/dist/src/interpreter/components/logic/LogicEngine.d.ts +0 -29
- package/dist/src/interpreter/components/logic/LogicEngine.js +0 -259
- package/dist/src/interpreter/components/logic/LogicResolver.d.ts +0 -53
- package/dist/src/interpreter/components/logic/LogicResolver.js +0 -484
- package/dist/src/interpreter/components/logic/LogicTranslator.d.ts +0 -14
- package/dist/src/interpreter/components/logic/LogicTranslator.js +0 -99
- package/dist/src/interpreter/components/runtimes/FunctionRuntime.d.ts +0 -12
- package/dist/src/interpreter/components/runtimes/FunctionRuntime.js +0 -149
- package/dist/src/interpreter/components/runtimes/LazyRuntime.d.ts +0 -19
- package/dist/src/interpreter/components/runtimes/LazyRuntime.js +0 -269
- package/dist/src/interpreter/components/runtimes/ObjectRuntime.d.ts +0 -35
- package/dist/src/interpreter/components/runtimes/ObjectRuntime.js +0 -126
- package/dist/src/interpreter/errors.d.ts +0 -19
- package/dist/src/interpreter/errors.js +0 -36
- package/dist/src/interpreter/index.d.ts +0 -24
- package/dist/src/interpreter/index.js +0 -41
- package/dist/src/interpreter/trampoline.d.ts +0 -17
- package/dist/src/interpreter/trampoline.js +0 -38
- package/dist/src/interpreter/utils.d.ts +0 -11
- package/dist/src/interpreter/utils.js +0 -65
- package/dist/src/tester/index.d.ts +0 -25
- package/dist/src/tester/index.js +0 -113
- package/dist/src/utils/helpers.d.ts +0 -13
- package/dist/src/utils/helpers.js +0 -52
- package/src/interpreter/components/Visitor.ts +0 -1065
- package/src/interpreter/trampoline.ts +0 -71
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import { YukigoKernel } from "../../src/interpreter/components/kernel/index.js";
|
|
3
|
+
import {
|
|
4
|
+
BindCommand,
|
|
5
|
+
EvalCommand,
|
|
6
|
+
ExecutionCommand,
|
|
7
|
+
FailCommand,
|
|
8
|
+
StepCommand,
|
|
9
|
+
} from "../../src/interpreter/components/kernel/commands.js";
|
|
10
|
+
import {
|
|
11
|
+
YuNil,
|
|
12
|
+
YuNumber,
|
|
13
|
+
YuString,
|
|
14
|
+
YuValue,
|
|
15
|
+
} from "../../src/interpreter/primitives/index.js";
|
|
16
|
+
import { Evaluator } from "../../src/interpreter/components/evaluators/BaseEvaluator.js";
|
|
17
|
+
|
|
18
|
+
describe("YukigoKernel", () => {
|
|
19
|
+
class MockEvaluator {
|
|
20
|
+
evaluate(node: any): ExecutionCommand {
|
|
21
|
+
return new StepCommand(node.mockValue);
|
|
22
|
+
}
|
|
23
|
+
getContext() {
|
|
24
|
+
return {
|
|
25
|
+
config: {
|
|
26
|
+
outputMode: "first",
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
let kernel: YukigoKernel;
|
|
33
|
+
|
|
34
|
+
beforeEach(() => {
|
|
35
|
+
kernel = new YukigoKernel(new MockEvaluator() as Evaluator);
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
it("must execute a StepCommand and end", () => {
|
|
39
|
+
const command = new StepCommand(new YuNumber(42));
|
|
40
|
+
const result = kernel.run(command) as YuNumber;
|
|
41
|
+
|
|
42
|
+
expect(result).to.be.instanceOf(YuNumber);
|
|
43
|
+
expect(result.value).to.equal(42);
|
|
44
|
+
expect(kernel.getLogicalTrace().length).to.eq(1);
|
|
45
|
+
expect(kernel.getLogicalTrace()[0].name).to.eq("STEP");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("must chain multiple commands via BindCommand", () => {
|
|
49
|
+
// Chain: (Step 10) -> (add 5) -> (multiply 2)
|
|
50
|
+
const command = new BindCommand(
|
|
51
|
+
new StepCommand(new YuNumber(10)),
|
|
52
|
+
(a) =>
|
|
53
|
+
new BindCommand(
|
|
54
|
+
new StepCommand(new YuNumber(5)),
|
|
55
|
+
(b) =>
|
|
56
|
+
new BindCommand(
|
|
57
|
+
a.asNumeric?.plus(b) || new StepCommand(YuNil.getInstance()),
|
|
58
|
+
(sum) =>
|
|
59
|
+
sum.asNumeric?.multiply(new YuNumber(2)) ||
|
|
60
|
+
new StepCommand(YuNil.getInstance()),
|
|
61
|
+
),
|
|
62
|
+
),
|
|
63
|
+
);
|
|
64
|
+
|
|
65
|
+
const result = kernel.run(command) as YuNumber;
|
|
66
|
+
|
|
67
|
+
expect(result).to.be.instanceOf(YuNumber);
|
|
68
|
+
expect(result.value).to.equal(30);
|
|
69
|
+
});
|
|
70
|
+
|
|
71
|
+
it("must delegate EvalCommand to injected Evaluator", () => {
|
|
72
|
+
const dummyNode = { type: "Dummy", mockValue: new YuNumber(99) } as any;
|
|
73
|
+
|
|
74
|
+
const command = new BindCommand(
|
|
75
|
+
new EvalCommand(dummyNode),
|
|
76
|
+
(val) => (val as YuNumber).plus(new YuNumber(1)), // 99 + 1
|
|
77
|
+
);
|
|
78
|
+
|
|
79
|
+
const result = kernel.run(command) as YuNumber;
|
|
80
|
+
|
|
81
|
+
expect(result).to.be.instanceOf(YuNumber);
|
|
82
|
+
expect(result.value).to.equal(100);
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("must abort execution if FailCommand is raised", () => {
|
|
86
|
+
const command = new BindCommand(
|
|
87
|
+
new StepCommand(new YuNumber(1)),
|
|
88
|
+
() => new FailCommand(new Error("Fallo simulado")),
|
|
89
|
+
);
|
|
90
|
+
|
|
91
|
+
expect(() => kernel.run(command)).to.throw(
|
|
92
|
+
"[Yukigo VM Error] Fallo simulado",
|
|
93
|
+
);
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
it("must not overflow with deep recursive steps (50000 iterations)", () => {
|
|
97
|
+
const iteraciones = new YuNumber(50000);
|
|
98
|
+
|
|
99
|
+
const recursiveStep = (count: YuNumber): ExecutionCommand => {
|
|
100
|
+
if (count.equals(new YuNumber(0)))
|
|
101
|
+
return new StepCommand(new YuString("fin"));
|
|
102
|
+
return new BindCommand(new StepCommand(count), () =>
|
|
103
|
+
recursiveStep(count.minus(new YuNumber(1)) as any),
|
|
104
|
+
);
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
const result = kernel.run(recursiveStep(iteraciones)) as YuValue;
|
|
108
|
+
|
|
109
|
+
expect(result).to.be.instanceOf(YuString);
|
|
110
|
+
expect((result as YuString).value).to.equal("fin");
|
|
111
|
+
});
|
|
112
|
+
});
|
|
@@ -1,152 +1,156 @@
|
|
|
1
|
-
import { expect } from "chai";
|
|
2
|
-
import {
|
|
3
|
-
Assert,
|
|
4
|
-
BooleanPrimitive,
|
|
5
|
-
Equality,
|
|
6
|
-
NumberPrimitive,
|
|
7
|
-
Sequence,
|
|
8
|
-
Test,
|
|
9
|
-
TestGroup,
|
|
10
|
-
StringPrimitive,
|
|
11
|
-
Variable,
|
|
12
|
-
SymbolPrimitive,
|
|
13
|
-
ArithmeticBinaryOperation,
|
|
14
|
-
Lambda,
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
);
|
|
84
|
-
|
|
85
|
-
const
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
expect(
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
new
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
);
|
|
119
|
-
|
|
120
|
-
const
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
),
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import {
|
|
3
|
+
Assert,
|
|
4
|
+
BooleanPrimitive,
|
|
5
|
+
Equality,
|
|
6
|
+
NumberPrimitive,
|
|
7
|
+
Sequence,
|
|
8
|
+
Test,
|
|
9
|
+
TestGroup,
|
|
10
|
+
StringPrimitive,
|
|
11
|
+
Variable,
|
|
12
|
+
SymbolPrimitive,
|
|
13
|
+
ArithmeticBinaryOperation,
|
|
14
|
+
Lambda,
|
|
15
|
+
Call,
|
|
16
|
+
Application,
|
|
17
|
+
VariablePattern,
|
|
18
|
+
Function,
|
|
19
|
+
Equation,
|
|
20
|
+
UnguardedBody,
|
|
21
|
+
Return,
|
|
22
|
+
} from "yukigo-ast";
|
|
23
|
+
import { Tester } from "../../src/tester/index.js";
|
|
24
|
+
|
|
25
|
+
describe("Tester class", () => {
|
|
26
|
+
it("should run a simple passing test", () => {
|
|
27
|
+
const passingTest = new Test(
|
|
28
|
+
new StringPrimitive("Success"),
|
|
29
|
+
new Sequence([
|
|
30
|
+
new Assert(
|
|
31
|
+
new BooleanPrimitive(false),
|
|
32
|
+
new Equality(new NumberPrimitive(1), new NumberPrimitive(1)),
|
|
33
|
+
),
|
|
34
|
+
]),
|
|
35
|
+
);
|
|
36
|
+
|
|
37
|
+
const tester = new Tester([passingTest]);
|
|
38
|
+
const results = tester.test([passingTest]);
|
|
39
|
+
|
|
40
|
+
expect(results).to.have.lengthOf(1);
|
|
41
|
+
expect(results[0].name).to.equal("Success");
|
|
42
|
+
expect(results[0].status).to.equal("passed");
|
|
43
|
+
});
|
|
44
|
+
|
|
45
|
+
it("should report a failing test with a message", () => {
|
|
46
|
+
const failingTest = new Test(
|
|
47
|
+
new StringPrimitive("Failure"),
|
|
48
|
+
new Sequence([
|
|
49
|
+
new Assert(
|
|
50
|
+
new BooleanPrimitive(false),
|
|
51
|
+
new Equality(new NumberPrimitive(1), new NumberPrimitive(2)),
|
|
52
|
+
),
|
|
53
|
+
]),
|
|
54
|
+
);
|
|
55
|
+
|
|
56
|
+
const tester = new Tester([failingTest]);
|
|
57
|
+
const results = tester.test([failingTest]);
|
|
58
|
+
|
|
59
|
+
expect(results).to.have.lengthOf(1);
|
|
60
|
+
expect(results[0].status).to.equal("failed");
|
|
61
|
+
expect(results[0].message).to.contain("Expected 1, but got 2");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("should run tests inside a TestGroup independently", () => {
|
|
65
|
+
const passingTest = new Test(
|
|
66
|
+
new StringPrimitive("Pass"),
|
|
67
|
+
new Sequence([
|
|
68
|
+
new Assert(
|
|
69
|
+
new BooleanPrimitive(false),
|
|
70
|
+
new Equality(new NumberPrimitive(10), new NumberPrimitive(10)),
|
|
71
|
+
),
|
|
72
|
+
]),
|
|
73
|
+
);
|
|
74
|
+
|
|
75
|
+
const failingTest = new Test(
|
|
76
|
+
new StringPrimitive("Fail"),
|
|
77
|
+
new Sequence([
|
|
78
|
+
new Assert(
|
|
79
|
+
new BooleanPrimitive(false),
|
|
80
|
+
new Equality(new NumberPrimitive(1), new NumberPrimitive(0)),
|
|
81
|
+
),
|
|
82
|
+
]),
|
|
83
|
+
);
|
|
84
|
+
|
|
85
|
+
const group = new TestGroup(
|
|
86
|
+
new StringPrimitive("My Group"),
|
|
87
|
+
new Sequence([passingTest, failingTest]),
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
const tester = new Tester([group]);
|
|
91
|
+
const results = tester.test([group]);
|
|
92
|
+
|
|
93
|
+
expect(results).to.have.lengthOf(1);
|
|
94
|
+
const groupReport = results[0];
|
|
95
|
+
expect(groupReport.name).to.equal("My Group");
|
|
96
|
+
expect(groupReport.status).to.equal("failed");
|
|
97
|
+
expect(groupReport.children).to.have.lengthOf(2);
|
|
98
|
+
expect(groupReport.children![0].status).to.equal("passed");
|
|
99
|
+
expect(groupReport.children![1].status).to.equal("failed");
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
it("should handle setup code inside a TestGroup", () => {
|
|
103
|
+
// var x = 5
|
|
104
|
+
const setup = new Variable(
|
|
105
|
+
new SymbolPrimitive("x"),
|
|
106
|
+
new NumberPrimitive(5),
|
|
107
|
+
);
|
|
108
|
+
|
|
109
|
+
// test "Check X" { assert x == 5 }
|
|
110
|
+
const checkX = new Test(
|
|
111
|
+
new StringPrimitive("Check X"),
|
|
112
|
+
new Sequence([
|
|
113
|
+
new Assert(
|
|
114
|
+
new BooleanPrimitive(false),
|
|
115
|
+
new Equality(new SymbolPrimitive("x"), new NumberPrimitive(5)),
|
|
116
|
+
),
|
|
117
|
+
]),
|
|
118
|
+
);
|
|
119
|
+
|
|
120
|
+
const group = new TestGroup(
|
|
121
|
+
new StringPrimitive("Setup Group"),
|
|
122
|
+
new Sequence([setup, checkX]),
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const tester = new Tester([group]);
|
|
126
|
+
const results = tester.test([group]);
|
|
127
|
+
|
|
128
|
+
expect(results[0].children).to.have.lengthOf(1);
|
|
129
|
+
expect(results[0].children![0].status).to.equal("passed");
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("should report errors that are not FailedAssert", () => {
|
|
133
|
+
// test "Error" { 1 * "a" }
|
|
134
|
+
const errorTest = new Test(
|
|
135
|
+
new StringPrimitive("Error"),
|
|
136
|
+
new Sequence([
|
|
137
|
+
new Application(
|
|
138
|
+
new Lambda(
|
|
139
|
+
[new VariablePattern(new SymbolPrimitive("b"))],
|
|
140
|
+
new ArithmeticBinaryOperation(
|
|
141
|
+
"Multiply",
|
|
142
|
+
new SymbolPrimitive("b"),
|
|
143
|
+
new StringPrimitive("a"),
|
|
144
|
+
),
|
|
145
|
+
),
|
|
146
|
+
new NumberPrimitive(1),
|
|
147
|
+
),
|
|
148
|
+
]),
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
const tester = new Tester([errorTest]);
|
|
152
|
+
const results = tester.test([errorTest]);
|
|
153
|
+
expect(results[0].status).to.equal("error");
|
|
154
|
+
expect(results[0].message).to.contain("Type mismatch");
|
|
155
|
+
});
|
|
156
|
+
});
|
package/tsconfig.build.json
CHANGED
|
@@ -1,15 +1,16 @@
|
|
|
1
|
-
{
|
|
2
|
-
"extends": "./tsconfig.json",
|
|
3
|
-
"compilerOptions": {
|
|
4
|
-
"noEmit": false
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
1
|
+
{
|
|
2
|
+
"extends": "./tsconfig.json",
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
"noEmit": false,
|
|
5
|
+
"rootDir": "src"
|
|
6
|
+
},
|
|
7
|
+
"exclude": [
|
|
8
|
+
"dist/**/*",
|
|
9
|
+
"tests/**/*"
|
|
10
|
+
],
|
|
11
|
+
"references": [
|
|
12
|
+
{
|
|
13
|
+
"path": "../yukigo-ast"
|
|
14
|
+
}
|
|
15
|
+
],
|
|
16
|
+
}
|
package/tsconfig.json
CHANGED
|
@@ -1,25 +1,27 @@
|
|
|
1
|
-
{
|
|
2
|
-
"compilerOptions": {
|
|
3
|
-
"target": "
|
|
4
|
-
"experimentalDecorators": true,
|
|
5
|
-
"module": "nodenext",
|
|
6
|
-
"moduleResolution": "nodenext",
|
|
7
|
-
"lib": ["
|
|
8
|
-
"outDir": "./dist",
|
|
9
|
-
"
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
14
|
-
"
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "es2025",
|
|
4
|
+
"experimentalDecorators": true,
|
|
5
|
+
"module": "nodenext",
|
|
6
|
+
"moduleResolution": "nodenext",
|
|
7
|
+
"lib": ["es2025", "dom"],
|
|
8
|
+
"outDir": "./dist",
|
|
9
|
+
"rootDir": "./",
|
|
10
|
+
"declaration": true,
|
|
11
|
+
"esModuleInterop": true,
|
|
12
|
+
"allowSyntheticDefaultImports": true,
|
|
13
|
+
"forceConsistentCasingInFileNames": true,
|
|
14
|
+
"skipLibCheck": true,
|
|
15
|
+
"noEmit": true,
|
|
16
|
+
"types": ["node", "mocha", "chai"]
|
|
17
|
+
},
|
|
18
|
+
"include": ["src/**/*", "tests/**/*"],
|
|
19
|
+
"exclude": [
|
|
20
|
+
"dist/**/*"
|
|
21
|
+
],
|
|
22
|
+
"references": [
|
|
23
|
+
{
|
|
24
|
+
"path": "../yukigo-ast"
|
|
25
|
+
}
|
|
26
|
+
]
|
|
27
|
+
}
|
|
@@ -1,70 +0,0 @@
|
|
|
1
|
-
import { Visitor, PrimitiveValue, NumberPrimitive, BooleanPrimitive, StringPrimitive, ListPrimitive, NilPrimitive, SymbolPrimitive, Variable, CharPrimitive, ArithmeticUnaryOperation, ArithmeticBinaryOperation, ListUnaryOperation, ListBinaryOperation, ComparisonOperation, LogicalBinaryOperation, LogicalUnaryOperation, BitwiseBinaryOperation, BitwiseUnaryOperation, StringOperation, UnifyOperation, AssignOperation, Assignment, TupleExpression, FieldExpression, DataExpression, ConsExpression, LetInExpression, Call, Otherwise, CompositionExpression, Expression, Application, Lambda, Sequence, Exist, Not, Findall, Forall, Goal, Send, New, Self, ListComprehension, RangeExpression, Generator as YuGenerator, ASTNode, Raise, Query, TypeCast, Super, If, Assert, Test, TestGroup, LogicConstraint } from "yukigo-ast";
|
|
2
|
-
import { ExpressionEvaluator } from "../utils.js";
|
|
3
|
-
import { ErrorFrame } from "../errors.js";
|
|
4
|
-
import { Continuation, CPSThunk, Thunk } from "../trampoline.js";
|
|
5
|
-
import { RuntimeContext } from "./RuntimeContext.js";
|
|
6
|
-
export declare class InterpreterVisitor implements Visitor<CPSThunk<PrimitiveValue>>, ExpressionEvaluator {
|
|
7
|
-
private context;
|
|
8
|
-
private frames;
|
|
9
|
-
constructor(context: RuntimeContext, frames?: ErrorFrame[]);
|
|
10
|
-
evaluate<R = PrimitiveValue>(node: ASTNode, cont: Continuation<PrimitiveValue, R>): Thunk<R>;
|
|
11
|
-
visitSequence(node: Sequence): CPSThunk<PrimitiveValue>;
|
|
12
|
-
visitAssert(node: Assert): CPSThunk<PrimitiveValue>;
|
|
13
|
-
visitTest(node: Test): CPSThunk<PrimitiveValue>;
|
|
14
|
-
visitTestGroup(node: TestGroup): CPSThunk<PrimitiveValue>;
|
|
15
|
-
visitNumberPrimitive(node: NumberPrimitive): CPSThunk<PrimitiveValue>;
|
|
16
|
-
visitBooleanPrimitive(node: BooleanPrimitive): CPSThunk<PrimitiveValue>;
|
|
17
|
-
visitStringPrimitive(node: StringPrimitive): CPSThunk<PrimitiveValue>;
|
|
18
|
-
visitListPrimitive(node: ListPrimitive): CPSThunk<PrimitiveValue>;
|
|
19
|
-
visitNilPrimitive(node: NilPrimitive): CPSThunk<PrimitiveValue>;
|
|
20
|
-
visitCharPrimitive(node: CharPrimitive): CPSThunk<PrimitiveValue>;
|
|
21
|
-
visitSymbolPrimitive(node: SymbolPrimitive): CPSThunk<PrimitiveValue>;
|
|
22
|
-
visitVariable(node: Variable): CPSThunk<PrimitiveValue>;
|
|
23
|
-
visitAssignment(node: Assignment): CPSThunk<PrimitiveValue>;
|
|
24
|
-
visitArithmeticUnaryOperation(node: ArithmeticUnaryOperation): CPSThunk<PrimitiveValue>;
|
|
25
|
-
visitArithmeticBinaryOperation(node: ArithmeticBinaryOperation): CPSThunk<PrimitiveValue>;
|
|
26
|
-
visitListUnaryOperation(node: ListUnaryOperation): CPSThunk<PrimitiveValue>;
|
|
27
|
-
visitListBinaryOperation(node: ListBinaryOperation): CPSThunk<PrimitiveValue>;
|
|
28
|
-
visitComparisonOperation(node: ComparisonOperation): CPSThunk<PrimitiveValue>;
|
|
29
|
-
visitLogicalBinaryOperation(node: LogicalBinaryOperation): CPSThunk<PrimitiveValue>;
|
|
30
|
-
visitLogicalUnaryOperation(node: LogicalUnaryOperation): CPSThunk<PrimitiveValue>;
|
|
31
|
-
visitBitwiseBinaryOperation(node: BitwiseBinaryOperation): CPSThunk<PrimitiveValue>;
|
|
32
|
-
visitBitwiseUnaryOperation(node: BitwiseUnaryOperation): CPSThunk<PrimitiveValue>;
|
|
33
|
-
visitStringOperation(node: StringOperation): CPSThunk<PrimitiveValue>;
|
|
34
|
-
visitUnifyOperation(node: UnifyOperation): CPSThunk<PrimitiveValue>;
|
|
35
|
-
visitAssignOperation(node: AssignOperation): CPSThunk<PrimitiveValue>;
|
|
36
|
-
visitTupleExpr(node: TupleExpression): CPSThunk<PrimitiveValue>;
|
|
37
|
-
visitFieldExpression(node: FieldExpression): CPSThunk<PrimitiveValue>;
|
|
38
|
-
visitDataExpr(node: DataExpression): CPSThunk<PrimitiveValue>;
|
|
39
|
-
visitConsExpr(node: ConsExpression): CPSThunk<PrimitiveValue>;
|
|
40
|
-
visitLetInExpr(node: LetInExpression): CPSThunk<PrimitiveValue>;
|
|
41
|
-
visitIf(node: If): CPSThunk<PrimitiveValue>;
|
|
42
|
-
visitCall(node: Call): CPSThunk<PrimitiveValue>;
|
|
43
|
-
visitOtherwise(node: Otherwise): CPSThunk<PrimitiveValue>;
|
|
44
|
-
visitCompositionExpression(node: CompositionExpression): CPSThunk<PrimitiveValue>;
|
|
45
|
-
visitLambda(node: Lambda): CPSThunk<PrimitiveValue>;
|
|
46
|
-
visitApplication(node: Application): CPSThunk<PrimitiveValue>;
|
|
47
|
-
visitQuery(node: Query): CPSThunk<PrimitiveValue>;
|
|
48
|
-
visitExist(node: Exist): CPSThunk<PrimitiveValue>;
|
|
49
|
-
visitNot(node: Not): CPSThunk<PrimitiveValue>;
|
|
50
|
-
visitFindall(node: Findall): CPSThunk<PrimitiveValue>;
|
|
51
|
-
visitForall(node: Forall): CPSThunk<PrimitiveValue>;
|
|
52
|
-
visitGoal(node: Goal): CPSThunk<PrimitiveValue>;
|
|
53
|
-
private bindLogicResults;
|
|
54
|
-
visitLogicConstraint(node: LogicConstraint): CPSThunk<PrimitiveValue>;
|
|
55
|
-
visitSuper(node: Super): CPSThunk<PrimitiveValue>;
|
|
56
|
-
visitSend(node: Send): CPSThunk<PrimitiveValue>;
|
|
57
|
-
visitNew(node: New): CPSThunk<PrimitiveValue>;
|
|
58
|
-
visitSelf(node: Self): CPSThunk<PrimitiveValue>;
|
|
59
|
-
visitListComprehension(node: ListComprehension): CPSThunk<PrimitiveValue>;
|
|
60
|
-
visitTypeCast(node: TypeCast): CPSThunk<PrimitiveValue>;
|
|
61
|
-
visitGenerator(node: YuGenerator): CPSThunk<PrimitiveValue>;
|
|
62
|
-
visitRaise(node: Raise): CPSThunk<PrimitiveValue>;
|
|
63
|
-
visitRangeExpression(node: RangeExpression): CPSThunk<PrimitiveValue>;
|
|
64
|
-
visit(node: Expression): CPSThunk<PrimitiveValue>;
|
|
65
|
-
realizeList<R = PrimitiveValue[]>(val: PrimitiveValue, k: Continuation<PrimitiveValue[], R>): Thunk<R>;
|
|
66
|
-
private processBinary;
|
|
67
|
-
private processUnary;
|
|
68
|
-
private getLogicEngine;
|
|
69
|
-
static evaluateLiteral(node: ASTNode): PrimitiveValue;
|
|
70
|
-
}
|