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.
Files changed (144) hide show
  1. package/.mocharc.json +3 -3
  2. package/CHANGELOG.md +26 -0
  3. package/README.md +193 -199
  4. package/dist/analyzer/GraphBuilder.d.ts +29 -0
  5. package/dist/analyzer/GraphBuilder.js +99 -0
  6. package/dist/analyzer/index.d.ts +11 -23
  7. package/dist/analyzer/index.js +100 -58
  8. package/dist/analyzer/inspections/functional/functional.d.ts +44 -0
  9. package/dist/analyzer/inspections/functional/functional.js +149 -0
  10. package/dist/analyzer/inspections/functional/smells.d.ts +16 -0
  11. package/dist/analyzer/inspections/functional/smells.js +98 -0
  12. package/dist/analyzer/inspections/{generic.d.ts → generic/generic.d.ts} +70 -43
  13. package/dist/analyzer/inspections/generic/generic.js +604 -0
  14. package/dist/analyzer/inspections/generic/smells.d.ts +61 -0
  15. package/dist/analyzer/inspections/generic/smells.js +349 -0
  16. package/dist/analyzer/inspections/imperative/imperative.d.ts +35 -0
  17. package/dist/analyzer/inspections/imperative/imperative.js +109 -0
  18. package/dist/analyzer/inspections/imperative/smells.d.ts +16 -0
  19. package/dist/analyzer/inspections/imperative/smells.js +58 -0
  20. package/dist/analyzer/inspections/logic/logic.d.ts +32 -0
  21. package/dist/analyzer/inspections/logic/logic.js +96 -0
  22. package/dist/analyzer/inspections/logic/smells.d.ts +15 -0
  23. package/dist/analyzer/inspections/logic/smells.js +60 -0
  24. package/dist/analyzer/inspections/object/object.d.ts +88 -0
  25. package/dist/analyzer/inspections/object/object.js +319 -0
  26. package/dist/analyzer/inspections/object/smells.d.ts +30 -0
  27. package/dist/analyzer/inspections/object/smells.js +135 -0
  28. package/dist/analyzer/utils.d.ts +26 -4
  29. package/dist/analyzer/utils.js +71 -13
  30. package/dist/index.d.ts +1 -0
  31. package/dist/index.js +1 -0
  32. package/dist/interpreter/components/EnvBuilder.d.ts +9 -5
  33. package/dist/interpreter/components/EnvBuilder.js +100 -30
  34. package/dist/interpreter/components/Operations.d.ts +4 -4
  35. package/dist/interpreter/components/Operations.js +17 -2
  36. package/dist/interpreter/components/PatternMatcher.d.ts +47 -17
  37. package/dist/interpreter/components/PatternMatcher.js +264 -119
  38. package/dist/interpreter/components/RuntimeContext.d.ts +35 -0
  39. package/dist/interpreter/components/RuntimeContext.js +93 -0
  40. package/dist/interpreter/components/TestRunner.d.ts +18 -0
  41. package/dist/interpreter/components/TestRunner.js +103 -0
  42. package/dist/interpreter/components/Visitor.d.ts +63 -57
  43. package/dist/interpreter/components/Visitor.js +508 -173
  44. package/dist/interpreter/components/logic/LogicEngine.d.ts +29 -0
  45. package/dist/interpreter/components/logic/LogicEngine.js +259 -0
  46. package/dist/interpreter/components/logic/LogicResolver.d.ts +53 -0
  47. package/dist/interpreter/components/logic/LogicResolver.js +471 -0
  48. package/dist/interpreter/components/logic/LogicTranslator.d.ts +14 -0
  49. package/dist/interpreter/components/logic/LogicTranslator.js +99 -0
  50. package/dist/interpreter/components/runtimes/FunctionRuntime.d.ts +12 -0
  51. package/dist/interpreter/components/runtimes/FunctionRuntime.js +147 -0
  52. package/dist/interpreter/components/runtimes/LazyRuntime.d.ts +19 -0
  53. package/dist/interpreter/components/runtimes/LazyRuntime.js +269 -0
  54. package/dist/interpreter/components/runtimes/ObjectRuntime.d.ts +35 -0
  55. package/dist/interpreter/components/runtimes/ObjectRuntime.js +126 -0
  56. package/dist/interpreter/entities.d.ts +105 -0
  57. package/dist/interpreter/entities.js +96 -0
  58. package/dist/interpreter/errors.d.ts +1 -1
  59. package/dist/interpreter/index.d.ts +4 -12
  60. package/dist/interpreter/index.js +10 -13
  61. package/dist/interpreter/trampoline.d.ts +17 -0
  62. package/dist/interpreter/trampoline.js +38 -0
  63. package/dist/interpreter/utils.d.ts +4 -7
  64. package/dist/interpreter/utils.js +25 -17
  65. package/dist/tester/index.d.ts +25 -0
  66. package/dist/tester/index.js +108 -0
  67. package/dist/utils/helpers.d.ts +0 -4
  68. package/dist/utils/helpers.js +20 -24
  69. package/package.json +2 -2
  70. package/src/analyzer/GraphBuilder.ts +142 -0
  71. package/src/analyzer/index.ts +185 -132
  72. package/src/analyzer/inspections/functional/functional.ts +121 -0
  73. package/src/analyzer/inspections/functional/smells.ts +102 -0
  74. package/src/analyzer/inspections/{generic.ts → generic/generic.ts} +581 -499
  75. package/src/analyzer/inspections/generic/smells.ts +365 -0
  76. package/src/analyzer/inspections/imperative/imperative.ts +101 -0
  77. package/src/analyzer/inspections/imperative/smells.ts +54 -0
  78. package/src/analyzer/inspections/logic/logic.ts +90 -0
  79. package/src/analyzer/inspections/logic/smells.ts +54 -0
  80. package/src/analyzer/inspections/{object.ts → object/object.ts} +264 -282
  81. package/src/analyzer/inspections/object/smells.ts +144 -0
  82. package/src/analyzer/utils.ts +109 -26
  83. package/src/index.ts +3 -2
  84. package/src/interpreter/components/EnvBuilder.ts +202 -97
  85. package/src/interpreter/components/Operations.ts +99 -81
  86. package/src/interpreter/components/PatternMatcher.ts +475 -254
  87. package/src/interpreter/components/RuntimeContext.ts +119 -0
  88. package/src/interpreter/components/TestRunner.ts +151 -0
  89. package/src/interpreter/components/Visitor.ts +1065 -493
  90. package/src/interpreter/components/logic/LogicEngine.ts +519 -0
  91. package/src/interpreter/components/logic/LogicResolver.ts +858 -0
  92. package/src/interpreter/components/logic/LogicTranslator.ts +149 -0
  93. package/src/interpreter/components/runtimes/FunctionRuntime.ts +227 -0
  94. package/src/interpreter/components/runtimes/LazyRuntime.ts +334 -0
  95. package/src/interpreter/components/runtimes/ObjectRuntime.ts +224 -0
  96. package/src/interpreter/errors.ts +47 -47
  97. package/src/interpreter/index.ts +52 -59
  98. package/src/interpreter/trampoline.ts +71 -0
  99. package/src/interpreter/utils.ts +84 -79
  100. package/src/tester/index.ts +128 -0
  101. package/src/utils/helpers.ts +67 -73
  102. package/tests/analyzer/functional.spec.ts +207 -221
  103. package/tests/analyzer/generic.spec.ts +178 -100
  104. package/tests/analyzer/helpers.spec.ts +83 -83
  105. package/tests/analyzer/logic.spec.ts +237 -292
  106. package/tests/analyzer/oop.spec.ts +323 -338
  107. package/tests/analyzer/transitive.spec.ts +166 -0
  108. package/tests/interpreter/EnvBuilder.spec.ts +183 -178
  109. package/tests/interpreter/FunctionRuntime.spec.ts +223 -234
  110. package/tests/interpreter/LazyRuntime.spec.ts +225 -190
  111. package/tests/interpreter/LogicEngine.spec.ts +327 -194
  112. package/tests/interpreter/LogicSubstitution.spec.ts +80 -0
  113. package/tests/interpreter/ObjectRuntime.spec.ts +606 -0
  114. package/tests/interpreter/Operations.spec.ts +220 -220
  115. package/tests/interpreter/PatternSystem.spec.ts +213 -189
  116. package/tests/interpreter/Tests.spec.ts +122 -0
  117. package/tests/interpreter/interpreter.spec.ts +991 -937
  118. package/tests/tester/Tester.spec.ts +153 -0
  119. package/tsconfig.build.json +15 -7
  120. package/tsconfig.json +25 -17
  121. package/dist/analyzer/inspections/functional.d.ts +0 -46
  122. package/dist/analyzer/inspections/functional.js +0 -123
  123. package/dist/analyzer/inspections/generic.js +0 -427
  124. package/dist/analyzer/inspections/imperative.d.ts +0 -37
  125. package/dist/analyzer/inspections/imperative.js +0 -105
  126. package/dist/analyzer/inspections/logic.d.ts +0 -49
  127. package/dist/analyzer/inspections/logic.js +0 -140
  128. package/dist/analyzer/inspections/object.d.ts +0 -83
  129. package/dist/analyzer/inspections/object.js +0 -235
  130. package/dist/interpreter/components/FunctionRuntime.d.ts +0 -8
  131. package/dist/interpreter/components/FunctionRuntime.js +0 -52
  132. package/dist/interpreter/components/LazyRuntime.d.ts +0 -7
  133. package/dist/interpreter/components/LazyRuntime.js +0 -75
  134. package/dist/interpreter/components/LogicEngine.d.ts +0 -21
  135. package/dist/interpreter/components/LogicEngine.js +0 -152
  136. package/dist/interpreter/components/LogicResolver.d.ts +0 -11
  137. package/dist/interpreter/components/LogicResolver.js +0 -87
  138. package/src/analyzer/inspections/functional.ts +0 -159
  139. package/src/analyzer/inspections/imperative.ts +0 -129
  140. package/src/analyzer/inspections/logic.ts +0 -166
  141. package/src/interpreter/components/FunctionRuntime.ts +0 -79
  142. package/src/interpreter/components/LazyRuntime.ts +0 -97
  143. package/src/interpreter/components/LogicEngine.ts +0 -227
  144. package/src/interpreter/components/LogicResolver.ts +0 -130
@@ -1,221 +1,207 @@
1
- import { expect } from "chai";
2
- import {
3
- Function,
4
- Equation,
5
- SymbolPrimitive,
6
- UnguardedBody,
7
- GuardedBody,
8
- Sequence,
9
- CompositionExpression,
10
- Lambda,
11
- Application,
12
- ListComprehension,
13
- Yield,
14
- LiteralPattern,
15
- ListPattern,
16
- WildcardPattern,
17
- BooleanPrimitive,
18
- NumberPrimitive,
19
- If,
20
- } from "yukigo-ast";
21
- import {
22
- UsesComposition,
23
- UsesAnonymousVariable,
24
- UsesComprehension,
25
- UsesGuards,
26
- UsesLambda,
27
- UsesYield,
28
- UsesPatternMatching,
29
- } from "../../src/analyzer/inspections/functional.js";
30
- import { executeVisitor } from "../../src/analyzer/utils.js";
31
-
32
- describe("Functional Spec", () => {
33
- const createSymbol = (name: string) => new SymbolPrimitive(name);
34
- const createSequence = (expr: any) => new Sequence([expr]);
35
- const createEquation = (patterns: any[], bodyExpr: any) => {
36
- const body = Array.isArray(bodyExpr)
37
- ? bodyExpr
38
- : new UnguardedBody(createSequence(bodyExpr));
39
-
40
- return new Equation(patterns, body, undefined);
41
- };
42
- const createFunction = (name: string, equations: Equation[]) => {
43
- return new Function(createSymbol(name), equations);
44
- };
45
- const mockExpr = new NumberPrimitive(1);
46
-
47
- describe("UsesGuards", () => {
48
- it("detects guards when they are present", () => {
49
- const guardedBody = new GuardedBody(mockExpr, mockExpr);
50
- const equation = new Equation([], [guardedBody, guardedBody], undefined);
51
- const func = createFunction("f", [equation]);
52
-
53
- const visitor = new UsesGuards("f");
54
- expect(executeVisitor(func, visitor)).to.eq(true);
55
- });
56
-
57
- it("does not detect guards when using UnguardedBody", () => {
58
- const equation = createEquation([], mockExpr);
59
- const func = createFunction("f", [equation]);
60
-
61
- const visitor = new UsesGuards("f");
62
- expect(executeVisitor(func, visitor)).to.eq(false);
63
- });
64
-
65
- it("should respect binding scope", () => {
66
- const guardedBody = new GuardedBody(mockExpr, mockExpr);
67
- const equation = new Equation([], [guardedBody], undefined);
68
- const func = createFunction("g", [equation]);
69
-
70
- const visitor = new UsesGuards("f");
71
- expect(executeVisitor(func, visitor)).to.eq(false);
72
- });
73
- });
74
-
75
- describe("UsesComposition", () => {
76
- const createComp = () => new CompositionExpression(mockExpr, mockExpr);
77
-
78
- it("is True when composition is present on top level", () => {
79
- const func = createFunction("x", [createEquation([], createComp())]);
80
-
81
- const visitor = new UsesComposition("x");
82
- expect(executeVisitor(func, visitor)).to.eq(true);
83
- });
84
-
85
- it("is True when composition is present inside lambda", () => {
86
- const lambda = new Lambda([], createComp());
87
- const func = createFunction("x", [createEquation([], lambda)]);
88
-
89
- const visitor = new UsesComposition("x");
90
- expect(executeVisitor(func, visitor)).to.eq(true);
91
- });
92
-
93
- it("is True when composition is present inside application", () => {
94
- const app = new Application(mockExpr, createComp());
95
- const func = createFunction("x", [createEquation([], app)]);
96
-
97
- const visitor = new UsesComposition("x");
98
- expect(executeVisitor(func, visitor)).to.eq(true);
99
- });
100
-
101
- it("is True when composition is present within if", () => {
102
- const ifExpr = new If(new BooleanPrimitive(true), createComp(), mockExpr);
103
- const func = createFunction("f", [createEquation([], ifExpr)]);
104
-
105
- const visitor = new UsesComposition("f");
106
- expect(executeVisitor(func, visitor)).to.eq(true);
107
- });
108
-
109
- it("is False when composition is not present", () => {
110
- const func = createFunction("x", [createEquation([], mockExpr)]);
111
- const visitor = new UsesComposition("x");
112
- expect(executeVisitor(func, visitor)).to.eq(false);
113
- });
114
- });
115
-
116
- describe("UsesPatternMatching", () => {
117
- it("is True when Pattern Matching with Literal", () => {
118
- const pattern = new LiteralPattern(new NumberPrimitive(0));
119
- const func = createFunction("factorial", [
120
- createEquation([pattern], mockExpr),
121
- ]);
122
-
123
- const visitor = new UsesPatternMatching("factorial");
124
- expect(executeVisitor(func, visitor)).to.eq(true);
125
- });
126
-
127
- it("is True when Pattern Matching on List", () => {
128
- const pattern = new ListPattern([]);
129
- const func = createFunction("foo", [createEquation([pattern], mockExpr)]);
130
-
131
- const visitor = new UsesPatternMatching("foo");
132
- expect(executeVisitor(func, visitor)).to.eq(true);
133
- });
134
-
135
- it("is True when Pattern Matching on anonymous variable (Wildcard)", () => {
136
- const pattern = new WildcardPattern();
137
- const func = createFunction("baz", [createEquation([pattern], mockExpr)]);
138
-
139
- const visitor = new UsesPatternMatching("baz");
140
- expect(executeVisitor(func, visitor)).to.eq(true);
141
- });
142
-
143
- it("is False when no patterns (or ignored patterns) are used", () => {
144
- const func = createFunction("foo", [createEquation([], mockExpr)]);
145
- const visitor = new UsesPatternMatching("foo");
146
- expect(executeVisitor(func, visitor)).to.eq(false);
147
- });
148
- });
149
-
150
- describe("UsesLambda", () => {
151
- it("detects lambda when is present", () => {
152
- const lambda = new Lambda([], mockExpr);
153
- const func = createFunction("f", [createEquation([], lambda)]);
154
-
155
- const visitor = new UsesLambda("f");
156
- expect(executeVisitor(func, visitor)).to.eq(true);
157
- });
158
-
159
- it("detects lambda when is not present", () => {
160
- const func = createFunction("f", [createEquation([], mockExpr)]);
161
- const visitor = new UsesLambda("f");
162
- expect(executeVisitor(func, visitor)).to.eq(false);
163
- });
164
- });
165
-
166
- describe("UsesAnonymousVariable", () => {
167
- it("is True if _ is present in parameters", () => {
168
- const pattern = new WildcardPattern();
169
- const func = createFunction("foo", [createEquation([pattern], mockExpr)]);
170
-
171
- const visitor = new UsesAnonymousVariable("foo");
172
- expect(executeVisitor(func, visitor)).to.eq(true);
173
- });
174
-
175
- it("is True if _ is present in nested structures (e.g. ListPattern)", () => {
176
- const innerWildcard = new WildcardPattern();
177
-
178
- const listPattern = new ListPattern([innerWildcard]);
179
-
180
- const func = createFunction("foo", [
181
- createEquation([listPattern], mockExpr),
182
- ]);
183
-
184
- const visitor = new UsesAnonymousVariable("foo");
185
-
186
- expect(executeVisitor(func, visitor)).to.eq(true);
187
- });
188
-
189
- it("is False if _ is not present", () => {
190
- const func = createFunction("foo", [createEquation([], mockExpr)]);
191
- const visitor = new UsesAnonymousVariable("foo");
192
- expect(executeVisitor(func, visitor)).to.eq(false);
193
- });
194
- });
195
-
196
- describe("UsesComprehension", () => {
197
- it("is True when list comprehension exists", () => {
198
- const comp = new ListComprehension(mockExpr, []);
199
- const func = createFunction("x", [createEquation([], comp)]);
200
-
201
- const visitor = new UsesComprehension(undefined);
202
- expect(executeVisitor(func, visitor)).to.eq(true);
203
- });
204
-
205
- it("is False when comprehension doesnt exists", () => {
206
- const func = createFunction("x", [createEquation([], mockExpr)]);
207
- const visitor = new UsesComprehension("x");
208
- expect(executeVisitor(func, visitor)).to.eq(false);
209
- });
210
- });
211
-
212
- describe("UsesYield", () => {
213
- it("is True when yield exists", () => {
214
- const yieldNode = new Yield(mockExpr);
215
- const func = createFunction("gen", [createEquation([], yieldNode)]);
216
-
217
- const visitor = new UsesYield("gen");
218
- expect(executeVisitor(func, visitor)).to.eq(true);
219
- });
220
- });
221
- });
1
+ import { expect } from "chai";
2
+ import {
3
+ Function,
4
+ Equation,
5
+ SymbolPrimitive,
6
+ UnguardedBody,
7
+ GuardedBody,
8
+ Sequence,
9
+ CompositionExpression,
10
+ Lambda,
11
+ Application,
12
+ ListComprehension,
13
+ Yield,
14
+ LiteralPattern,
15
+ ListPattern,
16
+ WildcardPattern,
17
+ BooleanPrimitive,
18
+ NumberPrimitive,
19
+ If,
20
+ TypeSignature,
21
+ SimpleType,
22
+ } from "yukigo-ast";
23
+ import { Analyzer, InspectionRule } from "../../src/analyzer/index.js";
24
+
25
+ describe("Functional Inspections", () => {
26
+ const createSymbol = (name: string) => new SymbolPrimitive(name);
27
+ const createSequence = (expr: any) => new Sequence([expr]);
28
+ const createEquation = (patterns: any[], bodyExpr: any) => {
29
+ const body = Array.isArray(bodyExpr)
30
+ ? bodyExpr
31
+ : new UnguardedBody(createSequence(bodyExpr));
32
+
33
+ return new Equation(patterns, body, undefined);
34
+ };
35
+ const createFunction = (name: string, equations: Equation[]) => {
36
+ return new Function(createSymbol(name), equations);
37
+ };
38
+ const mockExpr = new NumberPrimitive(1);
39
+ const analyzer = new Analyzer();
40
+
41
+ const runSingleRule = (
42
+ ast: any[],
43
+ inspection: string,
44
+ expected: boolean,
45
+ binding?: string,
46
+ args: string[] = []
47
+ ) => {
48
+ const rule: InspectionRule = { inspection, binding, args, expected };
49
+ const results = analyzer.analyze(ast, [rule]);
50
+ const result = results[0]; // Assuming only one rule is passed
51
+ return result.passed;
52
+ };
53
+
54
+ describe("UsesGuards", () => {
55
+ it("detects guards when they are present", () => {
56
+ const guardedBody = new GuardedBody(mockExpr, mockExpr);
57
+ const equation = new Equation([], [guardedBody, guardedBody], undefined);
58
+ const func = createFunction("f", [equation]);
59
+ expect(runSingleRule([func], "UsesGuards", true, "f")).to.be.true;
60
+ });
61
+
62
+ it("does not detect guards when using UnguardedBody", () => {
63
+ const equation = createEquation([], mockExpr);
64
+ const func = createFunction("f", [equation]);
65
+ expect(runSingleRule([func], "UsesGuards", false, "f")).to.be.true;
66
+ });
67
+
68
+ it("should respect binding scope", () => {
69
+ const guardedBody = new GuardedBody(mockExpr, mockExpr);
70
+ const equation = new Equation([], [guardedBody], undefined);
71
+ const func = createFunction("g", [equation]);
72
+ expect(runSingleRule([func], "UsesGuards", false, "f")).to.be.true;
73
+ });
74
+ });
75
+
76
+ describe("UsesComposition", () => {
77
+ const createComp = () => new CompositionExpression(mockExpr, mockExpr);
78
+
79
+ it("is True when composition is present on top level", () => {
80
+ const func = createFunction("x", [createEquation([], createComp())]);
81
+ expect(runSingleRule([func], "UsesComposition", true, "x")).to.be.true;
82
+ });
83
+
84
+ it("is True when composition is present inside lambda", () => {
85
+ const lambda = new Lambda([], createComp());
86
+ const func = createFunction("x", [createEquation([], lambda)]);
87
+ expect(runSingleRule([func], "UsesComposition", true, "x")).to.be.true;
88
+ });
89
+
90
+ it("is True when composition is present inside application", () => {
91
+ const app = new Application(mockExpr, createComp());
92
+ const func = createFunction("x", [createEquation([], app)]);
93
+ expect(runSingleRule([func], "UsesComposition", true, "x")).to.be.true;
94
+ });
95
+
96
+ it("is True when composition is present within if", () => {
97
+ const ifExpr = new If(new BooleanPrimitive(true), createComp(), mockExpr);
98
+ const func = createFunction("f", [createEquation([], ifExpr)]);
99
+ expect(runSingleRule([func], "UsesComposition", true, "f")).to.be.true;
100
+ });
101
+
102
+ it("is False when composition is not present", () => {
103
+ const func = createFunction("x", [createEquation([], mockExpr)]);
104
+ expect(runSingleRule([func], "UsesComposition", false, "x")).to.be.true;
105
+ });
106
+ });
107
+
108
+ describe("UsesPatternMatching", () => {
109
+ it("is True when Pattern Matching with Literal", () => {
110
+ const pattern = new LiteralPattern(new NumberPrimitive(0));
111
+ const func = createFunction("factorial", [
112
+ createEquation([pattern], mockExpr),
113
+ ]);
114
+ expect(runSingleRule([func], "UsesPatternMatching", true, "factorial")).to
115
+ .be.true;
116
+ });
117
+
118
+ it("is True when Pattern Matching on List", () => {
119
+ const pattern = new ListPattern([]);
120
+ const func = createFunction("foo", [createEquation([pattern], mockExpr)]);
121
+ expect(runSingleRule([func], "UsesPatternMatching", true, "foo")).to.be
122
+ .true;
123
+ });
124
+
125
+ it("is True when Pattern Matching on anonymous variable (Wildcard)", () => {
126
+ const pattern = new WildcardPattern();
127
+ const func = createFunction("baz", [createEquation([pattern], mockExpr)]);
128
+ expect(runSingleRule([func], "UsesPatternMatching", true, "baz")).to.be
129
+ .true;
130
+ });
131
+
132
+ it("is False when no patterns (or ignored patterns) are used", () => {
133
+ const func = createFunction("foo", [createEquation([], mockExpr)]);
134
+ expect(runSingleRule([func], "UsesPatternMatching", false, "foo")).to.be
135
+ .true;
136
+ });
137
+ });
138
+
139
+ describe("UsesLambda", () => {
140
+ it("detects lambda when is present", () => {
141
+ const lambda = new Lambda([], mockExpr);
142
+ const func = createFunction("f", [createEquation([], lambda)]);
143
+ expect(runSingleRule([func], "UsesLambda", true, "f")).to.be.true;
144
+ });
145
+
146
+ it("detects lambda when is not present", () => {
147
+ const func = createFunction("f", [createEquation([], mockExpr)]);
148
+ expect(runSingleRule([func], "UsesLambda", false, "f")).to.be.true;
149
+ });
150
+ });
151
+
152
+ describe("UsesAnonymousVariable", () => {
153
+ it("is True if _ is present in parameters", () => {
154
+ const pattern = new WildcardPattern();
155
+ const func = createFunction("foo", [createEquation([pattern], mockExpr)]);
156
+ expect(runSingleRule([func], "UsesAnonymousVariable", true, "foo")).to.be
157
+ .true;
158
+ });
159
+
160
+ it("is True if _ is present in nested structures (e.g. ListPattern)", () => {
161
+ const innerWildcard = new WildcardPattern();
162
+ const listPattern = new ListPattern([innerWildcard]);
163
+ const func = createFunction("foo", [
164
+ createEquation([listPattern], mockExpr),
165
+ ]);
166
+ expect(runSingleRule([func], "UsesAnonymousVariable", true, "foo")).to.be
167
+ .true;
168
+ });
169
+
170
+ it("is False if _ is not present", () => {
171
+ const func = createFunction("foo", [createEquation([], mockExpr)]);
172
+ expect(runSingleRule([func], "UsesAnonymousVariable", false, "foo")).to.be
173
+ .true;
174
+ });
175
+ });
176
+
177
+ describe("UsesComprehension", () => {
178
+ it("is True when list comprehension exists", () => {
179
+ const comp = new ListComprehension(mockExpr, []);
180
+ const func = createFunction("x", [createEquation([], comp)]);
181
+ expect(runSingleRule([func], "UsesComprehension", true, undefined)).to.be
182
+ .true;
183
+ });
184
+
185
+ it("is False when comprehension doesnt exists", () => {
186
+ const func = createFunction("x", [createEquation([], mockExpr)]);
187
+ expect(runSingleRule([func], "UsesComprehension", false, "x")).to.be.true;
188
+ });
189
+ });
190
+
191
+ describe("UsesYield", () => {
192
+ it("is True when yield exists", () => {
193
+ const yieldNode = new Yield(mockExpr);
194
+ const func = createFunction("gen", [createEquation([], yieldNode)]);
195
+ expect(runSingleRule([func], "UsesYield", true, "gen")).to.be.true;
196
+ });
197
+ });
198
+ describe("HasTypeSignature", () => {
199
+ it("is True when signature exists", () => {
200
+ const signature = new TypeSignature(
201
+ new SymbolPrimitive("MockType"),
202
+ new SimpleType("simple", [])
203
+ );
204
+ expect(runSingleRule([signature], "HasTypeSignature", true, "MockType")).to.be.true;
205
+ });
206
+ });
207
+ });