yukigo 0.1.0 → 0.2.0
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 +26 -0
- package/README.md +193 -199
- package/dist/analyzer/GraphBuilder.d.ts +29 -0
- package/dist/analyzer/GraphBuilder.js +99 -0
- package/dist/analyzer/index.d.ts +11 -23
- package/dist/analyzer/index.js +100 -58
- package/dist/analyzer/inspections/functional/functional.d.ts +44 -0
- package/dist/analyzer/inspections/functional/functional.js +149 -0
- package/dist/analyzer/inspections/functional/smells.d.ts +16 -0
- package/dist/analyzer/inspections/functional/smells.js +98 -0
- package/dist/analyzer/inspections/{generic.d.ts → generic/generic.d.ts} +70 -43
- package/dist/analyzer/inspections/generic/generic.js +604 -0
- package/dist/analyzer/inspections/generic/smells.d.ts +61 -0
- package/dist/analyzer/inspections/generic/smells.js +349 -0
- package/dist/analyzer/inspections/imperative/imperative.d.ts +35 -0
- package/dist/analyzer/inspections/imperative/imperative.js +109 -0
- package/dist/analyzer/inspections/imperative/smells.d.ts +16 -0
- package/dist/analyzer/inspections/imperative/smells.js +58 -0
- package/dist/analyzer/inspections/logic/logic.d.ts +32 -0
- package/dist/analyzer/inspections/logic/logic.js +96 -0
- package/dist/analyzer/inspections/logic/smells.d.ts +15 -0
- package/dist/analyzer/inspections/logic/smells.js +60 -0
- package/dist/analyzer/inspections/object/object.d.ts +88 -0
- package/dist/analyzer/inspections/object/object.js +319 -0
- package/dist/analyzer/inspections/object/smells.d.ts +30 -0
- package/dist/analyzer/inspections/object/smells.js +135 -0
- package/dist/analyzer/utils.d.ts +26 -4
- package/dist/analyzer/utils.js +71 -13
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/interpreter/components/EnvBuilder.d.ts +9 -5
- package/dist/interpreter/components/EnvBuilder.js +100 -30
- package/dist/interpreter/components/Operations.d.ts +4 -4
- package/dist/interpreter/components/Operations.js +17 -2
- package/dist/interpreter/components/PatternMatcher.d.ts +47 -17
- package/dist/interpreter/components/PatternMatcher.js +264 -119
- package/dist/interpreter/components/RuntimeContext.d.ts +35 -0
- package/dist/interpreter/components/RuntimeContext.js +93 -0
- package/dist/interpreter/components/TestRunner.d.ts +18 -0
- package/dist/interpreter/components/TestRunner.js +103 -0
- package/dist/interpreter/components/Visitor.d.ts +63 -57
- package/dist/interpreter/components/Visitor.js +508 -173
- package/dist/interpreter/components/logic/LogicEngine.d.ts +29 -0
- package/dist/interpreter/components/logic/LogicEngine.js +259 -0
- package/dist/interpreter/components/logic/LogicResolver.d.ts +53 -0
- package/dist/interpreter/components/logic/LogicResolver.js +471 -0
- package/dist/interpreter/components/logic/LogicTranslator.d.ts +14 -0
- package/dist/interpreter/components/logic/LogicTranslator.js +99 -0
- package/dist/interpreter/components/runtimes/FunctionRuntime.d.ts +12 -0
- package/dist/interpreter/components/runtimes/FunctionRuntime.js +147 -0
- package/dist/interpreter/components/runtimes/LazyRuntime.d.ts +19 -0
- package/dist/interpreter/components/runtimes/LazyRuntime.js +269 -0
- package/dist/interpreter/components/runtimes/ObjectRuntime.d.ts +35 -0
- package/dist/interpreter/components/runtimes/ObjectRuntime.js +126 -0
- package/dist/interpreter/entities.d.ts +105 -0
- package/dist/interpreter/entities.js +96 -0
- package/dist/interpreter/errors.d.ts +1 -1
- package/dist/interpreter/index.d.ts +4 -12
- package/dist/interpreter/index.js +10 -13
- package/dist/interpreter/trampoline.d.ts +17 -0
- package/dist/interpreter/trampoline.js +38 -0
- package/dist/interpreter/utils.d.ts +4 -7
- package/dist/interpreter/utils.js +25 -17
- package/dist/tester/index.d.ts +25 -0
- package/dist/tester/index.js +108 -0
- package/dist/utils/helpers.d.ts +0 -4
- package/dist/utils/helpers.js +20 -24
- package/package.json +2 -2
- package/src/analyzer/GraphBuilder.ts +142 -0
- package/src/analyzer/index.ts +185 -132
- package/src/analyzer/inspections/functional/functional.ts +121 -0
- package/src/analyzer/inspections/functional/smells.ts +102 -0
- package/src/analyzer/inspections/{generic.ts → generic/generic.ts} +581 -499
- package/src/analyzer/inspections/generic/smells.ts +365 -0
- package/src/analyzer/inspections/imperative/imperative.ts +101 -0
- package/src/analyzer/inspections/imperative/smells.ts +54 -0
- package/src/analyzer/inspections/logic/logic.ts +90 -0
- package/src/analyzer/inspections/logic/smells.ts +54 -0
- package/src/analyzer/inspections/{object.ts → object/object.ts} +264 -282
- package/src/analyzer/inspections/object/smells.ts +144 -0
- package/src/analyzer/utils.ts +109 -26
- package/src/index.ts +3 -2
- package/src/interpreter/components/EnvBuilder.ts +202 -97
- package/src/interpreter/components/Operations.ts +99 -81
- package/src/interpreter/components/PatternMatcher.ts +475 -254
- package/src/interpreter/components/RuntimeContext.ts +119 -0
- package/src/interpreter/components/TestRunner.ts +151 -0
- package/src/interpreter/components/Visitor.ts +1065 -493
- package/src/interpreter/components/logic/LogicEngine.ts +519 -0
- package/src/interpreter/components/logic/LogicResolver.ts +858 -0
- package/src/interpreter/components/logic/LogicTranslator.ts +149 -0
- package/src/interpreter/components/runtimes/FunctionRuntime.ts +227 -0
- package/src/interpreter/components/runtimes/LazyRuntime.ts +334 -0
- package/src/interpreter/components/runtimes/ObjectRuntime.ts +224 -0
- package/src/interpreter/errors.ts +47 -47
- package/src/interpreter/index.ts +52 -59
- package/src/interpreter/trampoline.ts +71 -0
- package/src/interpreter/utils.ts +84 -79
- package/src/tester/index.ts +128 -0
- package/src/utils/helpers.ts +67 -73
- package/tests/analyzer/functional.spec.ts +207 -221
- package/tests/analyzer/generic.spec.ts +178 -100
- package/tests/analyzer/helpers.spec.ts +83 -83
- package/tests/analyzer/logic.spec.ts +237 -292
- package/tests/analyzer/oop.spec.ts +323 -338
- package/tests/analyzer/transitive.spec.ts +166 -0
- package/tests/interpreter/EnvBuilder.spec.ts +183 -178
- package/tests/interpreter/FunctionRuntime.spec.ts +223 -234
- package/tests/interpreter/LazyRuntime.spec.ts +225 -190
- package/tests/interpreter/LogicEngine.spec.ts +327 -194
- package/tests/interpreter/LogicSubstitution.spec.ts +80 -0
- package/tests/interpreter/ObjectRuntime.spec.ts +606 -0
- package/tests/interpreter/Operations.spec.ts +220 -220
- package/tests/interpreter/PatternSystem.spec.ts +213 -189
- package/tests/interpreter/Tests.spec.ts +122 -0
- package/tests/interpreter/interpreter.spec.ts +991 -937
- package/tests/tester/Tester.spec.ts +153 -0
- package/tsconfig.build.json +15 -7
- package/tsconfig.json +25 -17
- package/dist/analyzer/inspections/functional.d.ts +0 -46
- package/dist/analyzer/inspections/functional.js +0 -123
- package/dist/analyzer/inspections/generic.js +0 -427
- package/dist/analyzer/inspections/imperative.d.ts +0 -37
- package/dist/analyzer/inspections/imperative.js +0 -105
- package/dist/analyzer/inspections/logic.d.ts +0 -49
- package/dist/analyzer/inspections/logic.js +0 -140
- package/dist/analyzer/inspections/object.d.ts +0 -83
- package/dist/analyzer/inspections/object.js +0 -235
- package/dist/interpreter/components/FunctionRuntime.d.ts +0 -8
- package/dist/interpreter/components/FunctionRuntime.js +0 -52
- package/dist/interpreter/components/LazyRuntime.d.ts +0 -7
- package/dist/interpreter/components/LazyRuntime.js +0 -75
- package/dist/interpreter/components/LogicEngine.d.ts +0 -21
- package/dist/interpreter/components/LogicEngine.js +0 -152
- package/dist/interpreter/components/LogicResolver.d.ts +0 -11
- package/dist/interpreter/components/LogicResolver.js +0 -87
- package/src/analyzer/inspections/functional.ts +0 -159
- package/src/analyzer/inspections/imperative.ts +0 -129
- package/src/analyzer/inspections/logic.ts +0 -166
- package/src/interpreter/components/FunctionRuntime.ts +0 -79
- package/src/interpreter/components/LazyRuntime.ts +0 -97
- package/src/interpreter/components/LogicEngine.ts +0 -227
- package/src/interpreter/components/LogicResolver.ts +0 -130
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import {
|
|
2
|
+
AST,
|
|
3
|
+
Expression,
|
|
4
|
+
Test,
|
|
5
|
+
TestGroup,
|
|
6
|
+
TraverseVisitor,
|
|
7
|
+
VariablePattern,
|
|
8
|
+
} from "yukigo-ast";
|
|
9
|
+
import { Interpreter } from "../interpreter/index.js";
|
|
10
|
+
import { FailedAssert } from "../interpreter/components/TestRunner.js";
|
|
11
|
+
import { InterpreterConfig } from "../interpreter/components/RuntimeContext.js";
|
|
12
|
+
|
|
13
|
+
export type TestStatus = "passed" | "failed" | "error";
|
|
14
|
+
|
|
15
|
+
export interface TestReport {
|
|
16
|
+
name: string;
|
|
17
|
+
status: TestStatus;
|
|
18
|
+
message?: string;
|
|
19
|
+
duration?: number;
|
|
20
|
+
children?: TestReport[];
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
class TestExecutor extends TraverseVisitor {
|
|
24
|
+
public report: TestReport | null = null;
|
|
25
|
+
constructor(private interpreter: Interpreter) {
|
|
26
|
+
super();
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
visitTest(node: Test): void {
|
|
30
|
+
const name = this.evaluateName(node.name);
|
|
31
|
+
const start = Date.now();
|
|
32
|
+
|
|
33
|
+
try {
|
|
34
|
+
//this.bindParameters(node);
|
|
35
|
+
this.interpreter.evaluate(node);
|
|
36
|
+
this.report = {
|
|
37
|
+
name,
|
|
38
|
+
status: "passed",
|
|
39
|
+
duration: Date.now() - start,
|
|
40
|
+
};
|
|
41
|
+
} catch (error) {
|
|
42
|
+
this.report = this.handleError(name, start, error);
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/* private bindParameters(node: Test): void {
|
|
47
|
+
if (!node.args || node.args.length === 0) return;
|
|
48
|
+
|
|
49
|
+
for (const pattern of node.args) {
|
|
50
|
+
if (pattern instanceof VariablePattern) {
|
|
51
|
+
this.interpreter.define(pattern.name.value, null);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
} */
|
|
55
|
+
|
|
56
|
+
visitTestGroup(node: TestGroup): void {
|
|
57
|
+
const name = this.evaluateName(node.name);
|
|
58
|
+
const start = Date.now();
|
|
59
|
+
|
|
60
|
+
try {
|
|
61
|
+
const children: TestReport[] = [];
|
|
62
|
+
for (const stmt of node.group.statements) {
|
|
63
|
+
if (stmt instanceof Test || stmt instanceof TestGroup) {
|
|
64
|
+
const visitor = new TestExecutor(this.interpreter);
|
|
65
|
+
stmt.accept(visitor);
|
|
66
|
+
if (visitor.report) children.push(visitor.report);
|
|
67
|
+
} else {
|
|
68
|
+
this.interpreter.evaluate(stmt);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const anyFailed = children.some((c) => c.status !== "passed");
|
|
72
|
+
this.report = {
|
|
73
|
+
name,
|
|
74
|
+
status: anyFailed ? "failed" : "passed",
|
|
75
|
+
duration: Date.now() - start,
|
|
76
|
+
children,
|
|
77
|
+
};
|
|
78
|
+
} catch (error) {
|
|
79
|
+
this.report = this.handleError(name, start, error);
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
private evaluateName(nameExpr: Expression): string {
|
|
84
|
+
try {
|
|
85
|
+
return String(this.interpreter.evaluate(nameExpr));
|
|
86
|
+
} catch {
|
|
87
|
+
return "Unknown Test";
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
private handleError(name: string, start: number, error: unknown): TestReport {
|
|
92
|
+
const duration = Date.now() - start;
|
|
93
|
+
if (error instanceof FailedAssert)
|
|
94
|
+
return { name, status: "failed", message: error.message, duration };
|
|
95
|
+
|
|
96
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
97
|
+
return { name, status: "error", message, duration };
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The Tester class provides a high-level API for executing test nodes
|
|
103
|
+
* (Tests and TestGroups) within an AST and generating a detailed report.
|
|
104
|
+
*/
|
|
105
|
+
export class Tester {
|
|
106
|
+
constructor(
|
|
107
|
+
private ast: AST,
|
|
108
|
+
private config?: InterpreterConfig,
|
|
109
|
+
) {}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Executes all Test and TestGroup nodes found at the top level of the provided AST.
|
|
113
|
+
* @param nodes The AST (or subset of nodes) to scan for tests.
|
|
114
|
+
* @returns An array of TestReport objects for each top-level test/group.
|
|
115
|
+
*/
|
|
116
|
+
public test(nodes: AST): TestReport[] {
|
|
117
|
+
const reports: TestReport[] = [];
|
|
118
|
+
for (const node of nodes) {
|
|
119
|
+
if (node instanceof Test || node instanceof TestGroup) {
|
|
120
|
+
const interpreter = new Interpreter(this.ast, this.config);
|
|
121
|
+
const visitor = new TestExecutor(interpreter);
|
|
122
|
+
node.accept(visitor);
|
|
123
|
+
reports.push(visitor.report);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
return reports;
|
|
127
|
+
}
|
|
128
|
+
}
|
package/src/utils/helpers.ts
CHANGED
|
@@ -1,73 +1,67 @@
|
|
|
1
|
-
import { parseDocument } from "yaml";
|
|
2
|
-
import { InspectionRule } from "../analyzer/index.js";
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
inspection
|
|
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
|
-
YuList: "YuList",
|
|
69
|
-
YuObject: "YuObject",
|
|
70
|
-
YuDict: "YuDict",
|
|
71
|
-
YuTuple: "YuTuple",
|
|
72
|
-
YuSymbol: "YuSymbol",
|
|
73
|
-
};
|
|
1
|
+
import { parseDocument } from "yaml";
|
|
2
|
+
import { InspectionRule } from "../analyzer/index.js";
|
|
3
|
+
|
|
4
|
+
type MulangInspection = {
|
|
5
|
+
inspection: string;
|
|
6
|
+
binding: string;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
const isValidFormat = (inspection: any): inspection is MulangInspection =>
|
|
10
|
+
typeof inspection === "object" &&
|
|
11
|
+
"inspection" in inspection &&
|
|
12
|
+
"binding" in inspection;
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Translates Mulang inspections (YAML format) to an array of `InspectionRule` objects.
|
|
16
|
+
* @param mulangYamlString The Mulang inspection syntax as a YAML string.
|
|
17
|
+
* @returns An array of InspectionRule objects.
|
|
18
|
+
*/
|
|
19
|
+
export class MulangAdapter {
|
|
20
|
+
public translateMulangInspection(mulangInspection: any): InspectionRule {
|
|
21
|
+
if (!isValidFormat(mulangInspection))
|
|
22
|
+
throw new Error(
|
|
23
|
+
`Skipping malformed Mulang inspection entry: ${mulangInspection}`
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
const inspection: string[] = mulangInspection.inspection.split(":");
|
|
27
|
+
const expected: boolean =
|
|
28
|
+
inspection[0] !== "Not" && inspection[0] !== "Except";
|
|
29
|
+
const args: string[] = inspection.slice(expected ? 1 : 2);
|
|
30
|
+
|
|
31
|
+
return {
|
|
32
|
+
inspection: expected ? inspection[0] : inspection[1],
|
|
33
|
+
expected,
|
|
34
|
+
args,
|
|
35
|
+
binding: mulangInspection.binding,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
public translateMulangExpectations(
|
|
40
|
+
mulangYamlString: string
|
|
41
|
+
): InspectionRule[] {
|
|
42
|
+
if (!mulangYamlString) return [];
|
|
43
|
+
const parsedYaml = parseDocument(mulangYamlString).toJS();
|
|
44
|
+
|
|
45
|
+
if (!parsedYaml) return [];
|
|
46
|
+
|
|
47
|
+
let expectations: any[] = [];
|
|
48
|
+
if (Array.isArray(parsedYaml)) {
|
|
49
|
+
expectations = parsedYaml;
|
|
50
|
+
} else if (Array.isArray(parsedYaml.expectations)) {
|
|
51
|
+
expectations = parsedYaml.expectations;
|
|
52
|
+
} else {
|
|
53
|
+
throw new Error(
|
|
54
|
+
"Invalid Mulang YAML structure. Expected 'expectations' to be an array."
|
|
55
|
+
);
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
const inspectionRules: InspectionRule[] = [];
|
|
59
|
+
|
|
60
|
+
for (const mulangInspection of expectations) {
|
|
61
|
+
const inspection = this.translateMulangInspection(mulangInspection);
|
|
62
|
+
inspectionRules.push(inspection);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
return inspectionRules;
|
|
66
|
+
}
|
|
67
|
+
}
|