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
|
@@ -1,292 +1,237 @@
|
|
|
1
|
-
import { expect } from "chai";
|
|
2
|
-
import {
|
|
3
|
-
Fact,
|
|
4
|
-
Rule,
|
|
5
|
-
SymbolPrimitive,
|
|
6
|
-
Exist,
|
|
7
|
-
Not,
|
|
8
|
-
Forall,
|
|
9
|
-
Findall,
|
|
10
|
-
AssignOperation,
|
|
11
|
-
UnifyOperation,
|
|
12
|
-
NumberPrimitive,
|
|
13
|
-
|
|
14
|
-
|
|
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
|
-
name
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
) => {
|
|
51
|
-
return new
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
const
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
const
|
|
70
|
-
expect((
|
|
71
|
-
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
const
|
|
94
|
-
expect((
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
const
|
|
120
|
-
expect((
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
it("
|
|
126
|
-
const
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
);
|
|
139
|
-
const rule = createRule("foo", [], [
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
);
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
it("
|
|
150
|
-
const
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
);
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
const
|
|
220
|
-
|
|
221
|
-
const
|
|
222
|
-
expect((
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
expect(() => executeVisitor(rule, visitor)).to.throw(
|
|
239
|
-
StopTraversalException
|
|
240
|
-
);
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
it("is True when there is a redundant reduction of literals (Var is 5)", () => {
|
|
244
|
-
const assign = new AssignOperation(
|
|
245
|
-
"Assign",
|
|
246
|
-
createSymbol("X"),
|
|
247
|
-
createNumber(5)
|
|
248
|
-
);
|
|
249
|
-
const rule = createRule("baz", [], [assign]);
|
|
250
|
-
|
|
251
|
-
const visitor = new HasRedundantReduction("baz");
|
|
252
|
-
expect(() => executeVisitor(rule, visitor)).to.throw(
|
|
253
|
-
StopTraversalException
|
|
254
|
-
);
|
|
255
|
-
});
|
|
256
|
-
|
|
257
|
-
it("is True when there is a redundant reduction of functors (Var is struct)", () => {
|
|
258
|
-
const functor = createCall("aFunctor", [createNumber(5)]);
|
|
259
|
-
const assign = new AssignOperation("Assign", createSymbol("Z"), functor);
|
|
260
|
-
const rule = createRule("baz", [], [assign]);
|
|
261
|
-
|
|
262
|
-
const visitor = new HasRedundantReduction("baz");
|
|
263
|
-
expect(() => executeVisitor(rule, visitor)).to.throw(
|
|
264
|
-
StopTraversalException
|
|
265
|
-
);
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it("is False when there is a complex reduction (operators)", () => {
|
|
269
|
-
const assign = new AssignOperation(
|
|
270
|
-
"Assign",
|
|
271
|
-
createSymbol("X"),
|
|
272
|
-
new ArithmeticBinaryOperation("Plus", createNumber(3), createNumber(2))
|
|
273
|
-
);
|
|
274
|
-
const rule = createRule("baz", [], [assign]);
|
|
275
|
-
|
|
276
|
-
const visitor = new HasRedundantReduction("baz");
|
|
277
|
-
expect(() => executeVisitor(rule, visitor)).to.not.throw();
|
|
278
|
-
});
|
|
279
|
-
|
|
280
|
-
it("respects bindings checks", () => {
|
|
281
|
-
const assign = new AssignOperation(
|
|
282
|
-
"Assign",
|
|
283
|
-
createSymbol("X"),
|
|
284
|
-
createNumber(5)
|
|
285
|
-
);
|
|
286
|
-
const rule = createRule("other", [], [assign]);
|
|
287
|
-
|
|
288
|
-
const visitor = new HasRedundantReduction("baz");
|
|
289
|
-
expect(() => executeVisitor(rule, visitor)).to.not.throw();
|
|
290
|
-
});
|
|
291
|
-
});
|
|
292
|
-
});
|
|
1
|
+
import { expect } from "chai";
|
|
2
|
+
import {
|
|
3
|
+
Fact,
|
|
4
|
+
Rule,
|
|
5
|
+
SymbolPrimitive,
|
|
6
|
+
Exist,
|
|
7
|
+
Not,
|
|
8
|
+
Forall,
|
|
9
|
+
Findall,
|
|
10
|
+
AssignOperation,
|
|
11
|
+
UnifyOperation,
|
|
12
|
+
NumberPrimitive,
|
|
13
|
+
ArithmeticBinaryOperation,
|
|
14
|
+
Equation,
|
|
15
|
+
UnguardedBody,
|
|
16
|
+
Sequence,
|
|
17
|
+
VariablePattern,
|
|
18
|
+
} from "yukigo-ast";
|
|
19
|
+
import {
|
|
20
|
+
Analyzer,
|
|
21
|
+
DefaultInspectionSet,
|
|
22
|
+
DefaultSmellsSet,
|
|
23
|
+
InspectionRule,
|
|
24
|
+
} from "../../src/analyzer/index.js";
|
|
25
|
+
|
|
26
|
+
describe("Logic Inspections", () => {
|
|
27
|
+
const createSymbol = (name: string) => new SymbolPrimitive(name);
|
|
28
|
+
const createNumber = (val: number) => new NumberPrimitive(val);
|
|
29
|
+
const analyzer = new Analyzer({
|
|
30
|
+
...DefaultInspectionSet,
|
|
31
|
+
...DefaultSmellsSet,
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const createFact = (name: string, args: any[] = []) => {
|
|
35
|
+
return new Fact(createSymbol(name), args);
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const createRule = (
|
|
39
|
+
name: string,
|
|
40
|
+
patterns: any[] = [],
|
|
41
|
+
bodyExprs: any[] = []
|
|
42
|
+
) => {
|
|
43
|
+
const equation = new Equation(
|
|
44
|
+
patterns,
|
|
45
|
+
new UnguardedBody(new Sequence(bodyExprs))
|
|
46
|
+
);
|
|
47
|
+
return new Rule(createSymbol(name), [equation]);
|
|
48
|
+
};
|
|
49
|
+
|
|
50
|
+
const createCall = (name: string, args: any[] = []) => {
|
|
51
|
+
return new Exist(createSymbol(name), args);
|
|
52
|
+
};
|
|
53
|
+
|
|
54
|
+
const runSingleRule = (
|
|
55
|
+
ast: any[],
|
|
56
|
+
inspection: string,
|
|
57
|
+
expected: boolean,
|
|
58
|
+
binding?: string,
|
|
59
|
+
args: string[] = []
|
|
60
|
+
) => {
|
|
61
|
+
const rule: InspectionRule = { inspection, binding, args, expected };
|
|
62
|
+
const results = analyzer.analyze(ast, [rule]);
|
|
63
|
+
const result = results[0]; // Assuming only one rule is passed
|
|
64
|
+
return result.passed;
|
|
65
|
+
};
|
|
66
|
+
|
|
67
|
+
describe("DeclaresFact", () => {
|
|
68
|
+
it("detects when a specific fact is declared", () => {
|
|
69
|
+
const fact = createFact("baz", [createSymbol("a")]);
|
|
70
|
+
expect(runSingleRule([fact], "DeclaresFact", true, "baz")).to.be.true;
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("ignores facts with different names", () => {
|
|
74
|
+
const fact = createFact("baz");
|
|
75
|
+
expect(runSingleRule([fact], "DeclaresFact", false, "foo")).to.be.true;
|
|
76
|
+
});
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
describe("DeclaresRule", () => {
|
|
80
|
+
it("detects when a specific rule is declared", () => {
|
|
81
|
+
const rule = createRule("foo");
|
|
82
|
+
expect(runSingleRule([rule], "DeclaresRule", true, "foo")).to.be.true;
|
|
83
|
+
});
|
|
84
|
+
|
|
85
|
+
it("ignores rules with different names", () => {
|
|
86
|
+
const rule = createRule("foo");
|
|
87
|
+
expect(runSingleRule([rule], "DeclaresRule", false, "baz")).to.be.true;
|
|
88
|
+
});
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
describe("DeclaresPredicate", () => {
|
|
92
|
+
it("is True when rule is declared", () => {
|
|
93
|
+
const rule = createRule("foo");
|
|
94
|
+
expect(runSingleRule([rule], "DeclaresPredicate", true, "foo")).to.be
|
|
95
|
+
.true;
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
it("is True when fact is declared", () => {
|
|
99
|
+
const fact = createFact("foo");
|
|
100
|
+
expect(runSingleRule([fact], "DeclaresPredicate", true, "foo")).to.be
|
|
101
|
+
.true;
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
it("is False when predicate is not declared", () => {
|
|
105
|
+
const fact = createFact("bar");
|
|
106
|
+
expect(runSingleRule([fact], "DeclaresPredicate", false, "foo")).to.be
|
|
107
|
+
.true;
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
describe("UsesForall", () => {
|
|
112
|
+
it("detects usage of forall/2", () => {
|
|
113
|
+
const forallNode = new Forall(createCall("cond"), createCall("action"));
|
|
114
|
+
const rule = createRule("foo", [], [forallNode]);
|
|
115
|
+
expect(runSingleRule([rule], "UsesForall", true)).to.be.true;
|
|
116
|
+
});
|
|
117
|
+
|
|
118
|
+
it("is False when not used", () => {
|
|
119
|
+
const rule = createRule("foo", [], [createCall("bar")]);
|
|
120
|
+
expect(runSingleRule([rule], "UsesForall", false)).to.be.true;
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
describe("UsesFindall", () => {
|
|
125
|
+
it("detects usage of findall/3", () => {
|
|
126
|
+
const findallNode = new Findall(
|
|
127
|
+
new VariablePattern(createSymbol("X")),
|
|
128
|
+
createCall("goal"),
|
|
129
|
+
new VariablePattern(createSymbol("L"))
|
|
130
|
+
);
|
|
131
|
+
const rule = createRule("foo", [], [findallNode]);
|
|
132
|
+
expect(runSingleRule([rule], "UsesFindall", true)).to.be.true;
|
|
133
|
+
});
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
describe("UsesNot", () => {
|
|
137
|
+
it("detects usage of Not node", () => {
|
|
138
|
+
const notNode = new Not(createCall("g"));
|
|
139
|
+
const rule = createRule("foo", [], [notNode]);
|
|
140
|
+
expect(runSingleRule([rule], "UsesNot", true)).to.be.true;
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("detects usage of 'not' as an Exist call (legacy/parsing variant)", () => {
|
|
144
|
+
const notCall = createCall("not", [createCall("g")]);
|
|
145
|
+
const rule = createRule("foo", [], [notCall]);
|
|
146
|
+
expect(runSingleRule([rule], "UsesNot", true)).to.be.true;
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("is False when not used", () => {
|
|
150
|
+
const rule = createRule("foo", [], [createCall("bar")]);
|
|
151
|
+
expect(runSingleRule([rule], "UsesNot", false)).to.be.true;
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
describe("UsesUnificationOperator", () => {
|
|
156
|
+
it("detects usage of unification (=)", () => {
|
|
157
|
+
const unify = new UnifyOperation(
|
|
158
|
+
"Unify",
|
|
159
|
+
createSymbol("X"),
|
|
160
|
+
createNumber(4)
|
|
161
|
+
);
|
|
162
|
+
const rule = createRule("baz", [], [unify]);
|
|
163
|
+
expect(runSingleRule([rule], "UsesUnificationOperator", true, "baz")).to
|
|
164
|
+
.be.true;
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
it("is False when no equal", () => {
|
|
168
|
+
const rule = createRule("baz", [], [createCall("other")]);
|
|
169
|
+
expect(runSingleRule([rule], "UsesUnificationOperator", false, "baz")).to
|
|
170
|
+
.be.true;
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
|
|
174
|
+
describe("UsesCut", () => {
|
|
175
|
+
it("detects usage of cut (!)", () => {
|
|
176
|
+
const cut = createCall("!");
|
|
177
|
+
const rule = createRule("baz", [], [cut]);
|
|
178
|
+
expect(runSingleRule([rule], "UsesCut", true, "baz")).to.be.true;
|
|
179
|
+
});
|
|
180
|
+
|
|
181
|
+
it("is False when not used", () => {
|
|
182
|
+
const rule = createRule("baz");
|
|
183
|
+
expect(runSingleRule([rule], "UsesCut", false, "baz")).to.be.true;
|
|
184
|
+
});
|
|
185
|
+
});
|
|
186
|
+
|
|
187
|
+
describe("UsesFail", () => {
|
|
188
|
+
it("detects usage of fail", () => {
|
|
189
|
+
const failNode = createCall("fail");
|
|
190
|
+
const rule = createRule("baz", [], [failNode]);
|
|
191
|
+
expect(runSingleRule([rule], "UsesFail", true, "baz")).to.be.true;
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
|
|
195
|
+
describe("HasRedundantReduction", () => {
|
|
196
|
+
it("is True when there is a redundant reduction of parameters (Var is Var)", () => {
|
|
197
|
+
const assign = new AssignOperation(
|
|
198
|
+
"Assign",
|
|
199
|
+
createSymbol("X"),
|
|
200
|
+
createSymbol("Y")
|
|
201
|
+
);
|
|
202
|
+
const rule = createRule("baz", [], [assign]);
|
|
203
|
+
expect(runSingleRule([rule], "HasRedundantReduction", true, "baz")).to.be
|
|
204
|
+
.true;
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("is True when there is a redundant reduction of literals (Var is 5)", () => {
|
|
208
|
+
const assign = new AssignOperation(
|
|
209
|
+
"Assign",
|
|
210
|
+
createSymbol("X"),
|
|
211
|
+
createNumber(5)
|
|
212
|
+
);
|
|
213
|
+
const rule = createRule("baz", [], [assign]);
|
|
214
|
+
expect(runSingleRule([rule], "HasRedundantReduction", true, "baz")).to.be
|
|
215
|
+
.true;
|
|
216
|
+
});
|
|
217
|
+
|
|
218
|
+
it("is True when there is a redundant reduction of functors (Var is struct)", () => {
|
|
219
|
+
const functor = createCall("aFunctor", [createNumber(5)]);
|
|
220
|
+
const assign = new AssignOperation("Assign", createSymbol("Z"), functor);
|
|
221
|
+
const rule = createRule("baz", [], [assign]);
|
|
222
|
+
expect(runSingleRule([rule], "HasRedundantReduction", true, "baz")).to.be
|
|
223
|
+
.true;
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("is False when there is a complex reduction (operators)", () => {
|
|
227
|
+
const assign = new AssignOperation(
|
|
228
|
+
"Assign",
|
|
229
|
+
createSymbol("X"),
|
|
230
|
+
new ArithmeticBinaryOperation("Plus", createNumber(3), createNumber(2))
|
|
231
|
+
);
|
|
232
|
+
const rule = createRule("baz", [], [assign]);
|
|
233
|
+
expect(runSingleRule([rule], "HasRedundantReduction", false, "baz")).to.be
|
|
234
|
+
.true;
|
|
235
|
+
});
|
|
236
|
+
});
|
|
237
|
+
});
|