trilean 1.5.1 → 1.6.1
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/dist/complex.d.cts +1 -1
- package/dist/complex.d.ts +1 -1
- package/dist/computed-value-CbRF0Izc.d.cts +51 -0
- package/dist/computed-value-CbRF0Izc.d.ts +51 -0
- package/dist/computed-value.cjs +1 -1
- package/dist/computed-value.d.cts +1 -50
- package/dist/computed-value.d.ts +1 -50
- package/dist/computed-value.js +1 -1
- package/dist/evaluator-budget.cjs +24 -0
- package/dist/evaluator-budget.d.cts +21 -0
- package/dist/evaluator-budget.d.ts +21 -0
- package/dist/evaluator-budget.js +20 -0
- package/dist/evaluator-collection.cjs +33 -0
- package/dist/evaluator-collection.d.cts +23 -0
- package/dist/evaluator-collection.d.ts +23 -0
- package/dist/evaluator-collection.js +31 -0
- package/dist/evaluator-factory.cjs +19 -0
- package/dist/evaluator-factory.d.cts +22 -0
- package/dist/evaluator-factory.d.ts +22 -0
- package/dist/evaluator-factory.js +16 -0
- package/dist/evaluator-indeterminacy-helpers.cjs +180 -0
- package/dist/evaluator-indeterminacy-helpers.d.cts +57 -0
- package/dist/evaluator-indeterminacy-helpers.d.ts +57 -0
- package/dist/evaluator-indeterminacy-helpers.js +158 -0
- package/dist/evaluator-operations.cjs +385 -0
- package/dist/evaluator-operations.d.cts +27 -0
- package/dist/evaluator-operations.d.ts +27 -0
- package/dist/evaluator-operations.js +376 -0
- package/dist/evaluator-test-helpers.cjs +40 -0
- package/dist/evaluator-test-helpers.d.cts +13 -0
- package/dist/evaluator-test-helpers.d.ts +13 -0
- package/dist/evaluator-test-helpers.js +35 -0
- package/dist/evaluator.cjs +55 -454
- package/dist/evaluator.d.cts +6 -10
- package/dist/evaluator.d.ts +6 -10
- package/dist/evaluator.js +44 -442
- package/dist/functions.d.cts +2 -2
- package/dist/functions.d.ts +2 -2
- package/dist/index.cjs +5 -5
- package/dist/index.d.cts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +2 -2
- package/dist/magic-string.es-BWtG0AyA.js +1017 -0
- package/dist/magic-string.es-BvKy4sJx.cjs +1017 -0
- package/dist/resolvers.d.cts +1 -1
- package/dist/resolvers.d.ts +1 -1
- package/dist/test.DNmyFkvJ-Dasq3mQO.cjs +13578 -0
- package/dist/test.DNmyFkvJ-SCEEf0VK.js +13573 -0
- package/package.json +2 -2
- package/schemas/trilean.schema.json +1 -1
|
@@ -0,0 +1,180 @@
|
|
|
1
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
|
+
const require_evaluator_factory = require("./evaluator-factory.cjs");
|
|
3
|
+
const require_test_DNmyFkvJ = require("./test.DNmyFkvJ-Dasq3mQO.cjs");
|
|
4
|
+
//#region src/evaluator-indeterminacy-helpers.ts
|
|
5
|
+
/**
|
|
6
|
+
* Shared fixture machinery for the two split indeterminacy test files (evaluator.indeterminacy-table.test.ts, evaluator.indeterminacy-cases.test.ts): systematic, table-driven coverage of README.md's "Indeterminacy reference" section, one fixture per node-kind x reason-code combination that section documents, for every `PredicateNode`/`ExpressionNode` kind implemented. This complements, rather than replaces, the ad hoc behavioural tests already spread across the evaluator.*.test.ts files and truth-tables.test.ts.
|
|
7
|
+
*/
|
|
8
|
+
function isPlainRecord(value) {
|
|
9
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
10
|
+
}
|
|
11
|
+
function isUnknownArray(value) {
|
|
12
|
+
return Array.isArray(value);
|
|
13
|
+
}
|
|
14
|
+
/** A single resolver pool shared by every fixture below, covering every named key/table/collection any fixture needs. Fixtures that need genuinely different resolver behaviour (the delegate/call rows) supply their own. */
|
|
15
|
+
const baseResolvers = {
|
|
16
|
+
resolveValue: async (key, context) => {
|
|
17
|
+
if (key === "present") return Promise.resolve({
|
|
18
|
+
found: true,
|
|
19
|
+
value: {
|
|
20
|
+
kind: "number",
|
|
21
|
+
value: 10,
|
|
22
|
+
unit: { m: 1 }
|
|
23
|
+
}
|
|
24
|
+
});
|
|
25
|
+
if (key === "presentText") return Promise.resolve({
|
|
26
|
+
found: true,
|
|
27
|
+
value: {
|
|
28
|
+
kind: "text",
|
|
29
|
+
value: "hello"
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
if (typeof key === "string" && isPlainRecord(context) && key in context) {
|
|
33
|
+
const value = context[key];
|
|
34
|
+
if (typeof value === "number") return Promise.resolve({
|
|
35
|
+
found: true,
|
|
36
|
+
value: {
|
|
37
|
+
kind: "number",
|
|
38
|
+
value
|
|
39
|
+
}
|
|
40
|
+
});
|
|
41
|
+
if (typeof value === "string") return Promise.resolve({
|
|
42
|
+
found: true,
|
|
43
|
+
value: {
|
|
44
|
+
kind: "text",
|
|
45
|
+
value
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
return Promise.resolve({ found: false });
|
|
50
|
+
},
|
|
51
|
+
resolveLookup: async (table) => {
|
|
52
|
+
if (table === "table1") return Promise.resolve({
|
|
53
|
+
found: true,
|
|
54
|
+
value: {
|
|
55
|
+
kind: "number",
|
|
56
|
+
value: 100
|
|
57
|
+
}
|
|
58
|
+
});
|
|
59
|
+
return Promise.resolve({ found: false });
|
|
60
|
+
},
|
|
61
|
+
resolveCollection: async (collection, context) => {
|
|
62
|
+
if (collection === "single-notfound") return Promise.resolve([{}]);
|
|
63
|
+
if (collection === "single-wrongtype") return Promise.resolve([{ value: "x" }]);
|
|
64
|
+
if (collection === "single-domainerror") return Promise.resolve([{}]);
|
|
65
|
+
if (collection === "empty") return Promise.resolve([]);
|
|
66
|
+
if (collection === "one-item") return Promise.resolve([{}]);
|
|
67
|
+
if (collection === "nested-outer") return Promise.resolve([{ values: [{ amount: 1 }, { amount: 2 }] }, { values: [{ amount: 10 }] }]);
|
|
68
|
+
if (collection === "values" && isPlainRecord(context)) {
|
|
69
|
+
const values = context.values;
|
|
70
|
+
return Promise.resolve(isUnknownArray(values) ? values : []);
|
|
71
|
+
}
|
|
72
|
+
return Promise.resolve([]);
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
const numberLiteral = (value) => ({
|
|
76
|
+
kind: "numberLiteral",
|
|
77
|
+
value
|
|
78
|
+
});
|
|
79
|
+
const missingRef = {
|
|
80
|
+
kind: "reference",
|
|
81
|
+
key: "missing"
|
|
82
|
+
};
|
|
83
|
+
const divideByZero = {
|
|
84
|
+
kind: "arithmetic",
|
|
85
|
+
op: "divide",
|
|
86
|
+
left: numberLiteral(1),
|
|
87
|
+
right: numberLiteral(0)
|
|
88
|
+
};
|
|
89
|
+
const wrongTypeArithmetic = {
|
|
90
|
+
kind: "arithmetic",
|
|
91
|
+
op: "add",
|
|
92
|
+
left: {
|
|
93
|
+
kind: "textLiteral",
|
|
94
|
+
value: "x"
|
|
95
|
+
},
|
|
96
|
+
right: numberLiteral(1)
|
|
97
|
+
};
|
|
98
|
+
const trueGuard = {
|
|
99
|
+
kind: "compare",
|
|
100
|
+
op: "eq",
|
|
101
|
+
left: numberLiteral(1),
|
|
102
|
+
right: numberLiteral(1)
|
|
103
|
+
};
|
|
104
|
+
const falseGuard = {
|
|
105
|
+
kind: "compare",
|
|
106
|
+
op: "eq",
|
|
107
|
+
left: numberLiteral(1),
|
|
108
|
+
right: numberLiteral(2)
|
|
109
|
+
};
|
|
110
|
+
const missingGuard = {
|
|
111
|
+
kind: "compare",
|
|
112
|
+
op: "eq",
|
|
113
|
+
left: missingRef,
|
|
114
|
+
right: numberLiteral(1)
|
|
115
|
+
};
|
|
116
|
+
/** Arbitrary non-`{-1,0,1,2}` magnitudes used below, named individually so each numeric literal only appears once (`@typescript-eslint/no-magic-numbers` only exempts -1/0/1/2 and object-literal property values, not values passed as plain call arguments). */
|
|
117
|
+
const memberOfProbeValue = 5;
|
|
118
|
+
const reduceInitialSeed = 5;
|
|
119
|
+
const laterConditionalCaseValue = 3;
|
|
120
|
+
const untouchedReduceInitial = 42;
|
|
121
|
+
const uniqueHitPolicyThirdCaseValue = 3;
|
|
122
|
+
const isDefinite = { status: "definite" };
|
|
123
|
+
const isNotFound = {
|
|
124
|
+
status: "indeterminate",
|
|
125
|
+
code: "not-found"
|
|
126
|
+
};
|
|
127
|
+
const isWrongType = {
|
|
128
|
+
status: "indeterminate",
|
|
129
|
+
code: "wrong-type"
|
|
130
|
+
};
|
|
131
|
+
const isDomainError = {
|
|
132
|
+
status: "indeterminate",
|
|
133
|
+
code: "domain-error"
|
|
134
|
+
};
|
|
135
|
+
function pred(description, node, expected, overrides = {}) {
|
|
136
|
+
const { context, resolvers = baseResolvers, functions } = overrides;
|
|
137
|
+
const { evaluatePredicate: evaluate } = functions ? require_evaluator_factory.createEvaluator({ functions }) : { evaluatePredicate: require_evaluator_factory.evaluatePredicate };
|
|
138
|
+
return {
|
|
139
|
+
description,
|
|
140
|
+
expected,
|
|
141
|
+
run: async () => evaluate(node, context, resolvers)
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
function expr(description, node, expected, overrides = {}) {
|
|
145
|
+
const { context, resolvers = baseResolvers, functions } = overrides;
|
|
146
|
+
const { evaluateValue: evaluate } = functions ? require_evaluator_factory.createEvaluator({ functions }) : { evaluateValue: require_evaluator_factory.evaluateValue };
|
|
147
|
+
return {
|
|
148
|
+
description,
|
|
149
|
+
expected,
|
|
150
|
+
run: async () => evaluate(node, context, resolvers)
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
async function runFixture({ run, expected }) {
|
|
154
|
+
const result = await run();
|
|
155
|
+
require_test_DNmyFkvJ.globalExpect(result.status).toBe(expected.status);
|
|
156
|
+
if (expected.status === "indeterminate" && result.status === "indeterminate") require_test_DNmyFkvJ.globalExpect(result.reason.code).toBe(expected.code);
|
|
157
|
+
}
|
|
158
|
+
//#endregion
|
|
159
|
+
exports.baseResolvers = baseResolvers;
|
|
160
|
+
exports.divideByZero = divideByZero;
|
|
161
|
+
exports.expr = expr;
|
|
162
|
+
exports.falseGuard = falseGuard;
|
|
163
|
+
exports.isDefinite = isDefinite;
|
|
164
|
+
exports.isDomainError = isDomainError;
|
|
165
|
+
exports.isNotFound = isNotFound;
|
|
166
|
+
exports.isPlainRecord = isPlainRecord;
|
|
167
|
+
exports.isUnknownArray = isUnknownArray;
|
|
168
|
+
exports.isWrongType = isWrongType;
|
|
169
|
+
exports.laterConditionalCaseValue = laterConditionalCaseValue;
|
|
170
|
+
exports.memberOfProbeValue = memberOfProbeValue;
|
|
171
|
+
exports.missingGuard = missingGuard;
|
|
172
|
+
exports.missingRef = missingRef;
|
|
173
|
+
exports.numberLiteral = numberLiteral;
|
|
174
|
+
exports.pred = pred;
|
|
175
|
+
exports.reduceInitialSeed = reduceInitialSeed;
|
|
176
|
+
exports.runFixture = runFixture;
|
|
177
|
+
exports.trueGuard = trueGuard;
|
|
178
|
+
exports.uniqueHitPolicyThirdCaseValue = uniqueHitPolicyThirdCaseValue;
|
|
179
|
+
exports.untouchedReduceInitial = untouchedReduceInitial;
|
|
180
|
+
exports.wrongTypeArithmetic = wrongTypeArithmetic;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ExpressionNode, PredicateNode } from "./tree.cjs";
|
|
2
|
+
import { IndeterminateReason } from "./evaluation.cjs";
|
|
3
|
+
import { FunctionRegistry } from "./functions.cjs";
|
|
4
|
+
import { EvaluationContext, Resolvers } from "./resolvers.cjs";
|
|
5
|
+
//#region src/evaluator-indeterminacy-helpers.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Shared fixture machinery for the two split indeterminacy test files (evaluator.indeterminacy-table.test.ts, evaluator.indeterminacy-cases.test.ts): systematic, table-driven coverage of README.md's "Indeterminacy reference" section, one fixture per node-kind x reason-code combination that section documents, for every `PredicateNode`/`ExpressionNode` kind implemented. This complements, rather than replaces, the ad hoc behavioural tests already spread across the evaluator.*.test.ts files and truth-tables.test.ts.
|
|
8
|
+
*/
|
|
9
|
+
declare function isPlainRecord(value: unknown): value is Record<string, unknown>;
|
|
10
|
+
declare function isUnknownArray(value: unknown): value is unknown[];
|
|
11
|
+
/** A single resolver pool shared by every fixture below, covering every named key/table/collection any fixture needs. Fixtures that need genuinely different resolver behaviour (the delegate/call rows) supply their own. */
|
|
12
|
+
declare const baseResolvers: Resolvers;
|
|
13
|
+
declare const numberLiteral: (value: number) => ExpressionNode;
|
|
14
|
+
declare const missingRef: ExpressionNode;
|
|
15
|
+
declare const divideByZero: ExpressionNode;
|
|
16
|
+
declare const wrongTypeArithmetic: ExpressionNode;
|
|
17
|
+
declare const trueGuard: PredicateNode;
|
|
18
|
+
declare const falseGuard: PredicateNode;
|
|
19
|
+
declare const missingGuard: PredicateNode;
|
|
20
|
+
/** Arbitrary non-`{-1,0,1,2}` magnitudes used below, named individually so each numeric literal only appears once (`@typescript-eslint/no-magic-numbers` only exempts -1/0/1/2 and object-literal property values, not values passed as plain call arguments). */
|
|
21
|
+
declare const memberOfProbeValue = 5;
|
|
22
|
+
declare const reduceInitialSeed = 5;
|
|
23
|
+
declare const laterConditionalCaseValue = 3;
|
|
24
|
+
declare const untouchedReduceInitial = 42;
|
|
25
|
+
declare const uniqueHitPolicyThirdCaseValue = 3;
|
|
26
|
+
type Expected = {
|
|
27
|
+
readonly status: "definite";
|
|
28
|
+
} | {
|
|
29
|
+
readonly status: "indeterminate";
|
|
30
|
+
readonly code: IndeterminateReason["code"];
|
|
31
|
+
};
|
|
32
|
+
declare const isDefinite: Expected;
|
|
33
|
+
declare const isNotFound: Expected;
|
|
34
|
+
declare const isWrongType: Expected;
|
|
35
|
+
declare const isDomainError: Expected;
|
|
36
|
+
/** The minimal shape `runFixture` needs from either `evaluatePredicate`'s or `evaluateValue`'s result -- both `Evaluation<boolean>` and `Evaluation<ComputedValue>` are structurally assignable here since only the indeterminate branch's `reason` is ever inspected, never the definite branch's `value`. Typing `Fixture.run`'s result as this proper discriminated union, rather than the looser `{ status: string }` it replaces, is what lets `runFixture` below narrow `result.reason` directly instead of needing a type assertion. */
|
|
37
|
+
type FixtureRunResult = {
|
|
38
|
+
readonly status: "definite";
|
|
39
|
+
} | {
|
|
40
|
+
readonly status: "indeterminate";
|
|
41
|
+
readonly reason: IndeterminateReason;
|
|
42
|
+
};
|
|
43
|
+
interface Fixture {
|
|
44
|
+
readonly description: string;
|
|
45
|
+
readonly expected: Expected;
|
|
46
|
+
readonly run: () => Promise<FixtureRunResult>;
|
|
47
|
+
}
|
|
48
|
+
interface FixtureOverrides {
|
|
49
|
+
readonly context?: EvaluationContext;
|
|
50
|
+
readonly resolvers?: Resolvers;
|
|
51
|
+
readonly functions?: FunctionRegistry;
|
|
52
|
+
}
|
|
53
|
+
declare function pred(description: string, node: PredicateNode, expected: Expected, overrides?: FixtureOverrides): Fixture;
|
|
54
|
+
declare function expr(description: string, node: ExpressionNode, expected: Expected, overrides?: FixtureOverrides): Fixture;
|
|
55
|
+
declare function runFixture({ run, expected }: Fixture): Promise<void>;
|
|
56
|
+
//#endregion
|
|
57
|
+
export { Expected, Fixture, FixtureOverrides, baseResolvers, divideByZero, expr, falseGuard, isDefinite, isDomainError, isNotFound, isPlainRecord, isUnknownArray, isWrongType, laterConditionalCaseValue, memberOfProbeValue, missingGuard, missingRef, numberLiteral, pred, reduceInitialSeed, runFixture, trueGuard, uniqueHitPolicyThirdCaseValue, untouchedReduceInitial, wrongTypeArithmetic };
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { ExpressionNode, PredicateNode } from "./tree.js";
|
|
2
|
+
import { IndeterminateReason } from "./evaluation.js";
|
|
3
|
+
import { FunctionRegistry } from "./functions.js";
|
|
4
|
+
import { EvaluationContext, Resolvers } from "./resolvers.js";
|
|
5
|
+
//#region src/evaluator-indeterminacy-helpers.d.ts
|
|
6
|
+
/**
|
|
7
|
+
* Shared fixture machinery for the two split indeterminacy test files (evaluator.indeterminacy-table.test.ts, evaluator.indeterminacy-cases.test.ts): systematic, table-driven coverage of README.md's "Indeterminacy reference" section, one fixture per node-kind x reason-code combination that section documents, for every `PredicateNode`/`ExpressionNode` kind implemented. This complements, rather than replaces, the ad hoc behavioural tests already spread across the evaluator.*.test.ts files and truth-tables.test.ts.
|
|
8
|
+
*/
|
|
9
|
+
declare function isPlainRecord(value: unknown): value is Record<string, unknown>;
|
|
10
|
+
declare function isUnknownArray(value: unknown): value is unknown[];
|
|
11
|
+
/** A single resolver pool shared by every fixture below, covering every named key/table/collection any fixture needs. Fixtures that need genuinely different resolver behaviour (the delegate/call rows) supply their own. */
|
|
12
|
+
declare const baseResolvers: Resolvers;
|
|
13
|
+
declare const numberLiteral: (value: number) => ExpressionNode;
|
|
14
|
+
declare const missingRef: ExpressionNode;
|
|
15
|
+
declare const divideByZero: ExpressionNode;
|
|
16
|
+
declare const wrongTypeArithmetic: ExpressionNode;
|
|
17
|
+
declare const trueGuard: PredicateNode;
|
|
18
|
+
declare const falseGuard: PredicateNode;
|
|
19
|
+
declare const missingGuard: PredicateNode;
|
|
20
|
+
/** Arbitrary non-`{-1,0,1,2}` magnitudes used below, named individually so each numeric literal only appears once (`@typescript-eslint/no-magic-numbers` only exempts -1/0/1/2 and object-literal property values, not values passed as plain call arguments). */
|
|
21
|
+
declare const memberOfProbeValue = 5;
|
|
22
|
+
declare const reduceInitialSeed = 5;
|
|
23
|
+
declare const laterConditionalCaseValue = 3;
|
|
24
|
+
declare const untouchedReduceInitial = 42;
|
|
25
|
+
declare const uniqueHitPolicyThirdCaseValue = 3;
|
|
26
|
+
type Expected = {
|
|
27
|
+
readonly status: "definite";
|
|
28
|
+
} | {
|
|
29
|
+
readonly status: "indeterminate";
|
|
30
|
+
readonly code: IndeterminateReason["code"];
|
|
31
|
+
};
|
|
32
|
+
declare const isDefinite: Expected;
|
|
33
|
+
declare const isNotFound: Expected;
|
|
34
|
+
declare const isWrongType: Expected;
|
|
35
|
+
declare const isDomainError: Expected;
|
|
36
|
+
/** The minimal shape `runFixture` needs from either `evaluatePredicate`'s or `evaluateValue`'s result -- both `Evaluation<boolean>` and `Evaluation<ComputedValue>` are structurally assignable here since only the indeterminate branch's `reason` is ever inspected, never the definite branch's `value`. Typing `Fixture.run`'s result as this proper discriminated union, rather than the looser `{ status: string }` it replaces, is what lets `runFixture` below narrow `result.reason` directly instead of needing a type assertion. */
|
|
37
|
+
type FixtureRunResult = {
|
|
38
|
+
readonly status: "definite";
|
|
39
|
+
} | {
|
|
40
|
+
readonly status: "indeterminate";
|
|
41
|
+
readonly reason: IndeterminateReason;
|
|
42
|
+
};
|
|
43
|
+
interface Fixture {
|
|
44
|
+
readonly description: string;
|
|
45
|
+
readonly expected: Expected;
|
|
46
|
+
readonly run: () => Promise<FixtureRunResult>;
|
|
47
|
+
}
|
|
48
|
+
interface FixtureOverrides {
|
|
49
|
+
readonly context?: EvaluationContext;
|
|
50
|
+
readonly resolvers?: Resolvers;
|
|
51
|
+
readonly functions?: FunctionRegistry;
|
|
52
|
+
}
|
|
53
|
+
declare function pred(description: string, node: PredicateNode, expected: Expected, overrides?: FixtureOverrides): Fixture;
|
|
54
|
+
declare function expr(description: string, node: ExpressionNode, expected: Expected, overrides?: FixtureOverrides): Fixture;
|
|
55
|
+
declare function runFixture({ run, expected }: Fixture): Promise<void>;
|
|
56
|
+
//#endregion
|
|
57
|
+
export { Expected, Fixture, FixtureOverrides, baseResolvers, divideByZero, expr, falseGuard, isDefinite, isDomainError, isNotFound, isPlainRecord, isUnknownArray, isWrongType, laterConditionalCaseValue, memberOfProbeValue, missingGuard, missingRef, numberLiteral, pred, reduceInitialSeed, runFixture, trueGuard, uniqueHitPolicyThirdCaseValue, untouchedReduceInitial, wrongTypeArithmetic };
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import { createEvaluator, evaluatePredicate, evaluateValue } from "./evaluator-factory.js";
|
|
2
|
+
import { t as globalExpect } from "./test.DNmyFkvJ-SCEEf0VK.js";
|
|
3
|
+
//#region src/evaluator-indeterminacy-helpers.ts
|
|
4
|
+
/**
|
|
5
|
+
* Shared fixture machinery for the two split indeterminacy test files (evaluator.indeterminacy-table.test.ts, evaluator.indeterminacy-cases.test.ts): systematic, table-driven coverage of README.md's "Indeterminacy reference" section, one fixture per node-kind x reason-code combination that section documents, for every `PredicateNode`/`ExpressionNode` kind implemented. This complements, rather than replaces, the ad hoc behavioural tests already spread across the evaluator.*.test.ts files and truth-tables.test.ts.
|
|
6
|
+
*/
|
|
7
|
+
function isPlainRecord(value) {
|
|
8
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
9
|
+
}
|
|
10
|
+
function isUnknownArray(value) {
|
|
11
|
+
return Array.isArray(value);
|
|
12
|
+
}
|
|
13
|
+
/** A single resolver pool shared by every fixture below, covering every named key/table/collection any fixture needs. Fixtures that need genuinely different resolver behaviour (the delegate/call rows) supply their own. */
|
|
14
|
+
const baseResolvers = {
|
|
15
|
+
resolveValue: async (key, context) => {
|
|
16
|
+
if (key === "present") return Promise.resolve({
|
|
17
|
+
found: true,
|
|
18
|
+
value: {
|
|
19
|
+
kind: "number",
|
|
20
|
+
value: 10,
|
|
21
|
+
unit: { m: 1 }
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
if (key === "presentText") return Promise.resolve({
|
|
25
|
+
found: true,
|
|
26
|
+
value: {
|
|
27
|
+
kind: "text",
|
|
28
|
+
value: "hello"
|
|
29
|
+
}
|
|
30
|
+
});
|
|
31
|
+
if (typeof key === "string" && isPlainRecord(context) && key in context) {
|
|
32
|
+
const value = context[key];
|
|
33
|
+
if (typeof value === "number") return Promise.resolve({
|
|
34
|
+
found: true,
|
|
35
|
+
value: {
|
|
36
|
+
kind: "number",
|
|
37
|
+
value
|
|
38
|
+
}
|
|
39
|
+
});
|
|
40
|
+
if (typeof value === "string") return Promise.resolve({
|
|
41
|
+
found: true,
|
|
42
|
+
value: {
|
|
43
|
+
kind: "text",
|
|
44
|
+
value
|
|
45
|
+
}
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
return Promise.resolve({ found: false });
|
|
49
|
+
},
|
|
50
|
+
resolveLookup: async (table) => {
|
|
51
|
+
if (table === "table1") return Promise.resolve({
|
|
52
|
+
found: true,
|
|
53
|
+
value: {
|
|
54
|
+
kind: "number",
|
|
55
|
+
value: 100
|
|
56
|
+
}
|
|
57
|
+
});
|
|
58
|
+
return Promise.resolve({ found: false });
|
|
59
|
+
},
|
|
60
|
+
resolveCollection: async (collection, context) => {
|
|
61
|
+
if (collection === "single-notfound") return Promise.resolve([{}]);
|
|
62
|
+
if (collection === "single-wrongtype") return Promise.resolve([{ value: "x" }]);
|
|
63
|
+
if (collection === "single-domainerror") return Promise.resolve([{}]);
|
|
64
|
+
if (collection === "empty") return Promise.resolve([]);
|
|
65
|
+
if (collection === "one-item") return Promise.resolve([{}]);
|
|
66
|
+
if (collection === "nested-outer") return Promise.resolve([{ values: [{ amount: 1 }, { amount: 2 }] }, { values: [{ amount: 10 }] }]);
|
|
67
|
+
if (collection === "values" && isPlainRecord(context)) {
|
|
68
|
+
const values = context.values;
|
|
69
|
+
return Promise.resolve(isUnknownArray(values) ? values : []);
|
|
70
|
+
}
|
|
71
|
+
return Promise.resolve([]);
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
const numberLiteral = (value) => ({
|
|
75
|
+
kind: "numberLiteral",
|
|
76
|
+
value
|
|
77
|
+
});
|
|
78
|
+
const missingRef = {
|
|
79
|
+
kind: "reference",
|
|
80
|
+
key: "missing"
|
|
81
|
+
};
|
|
82
|
+
const divideByZero = {
|
|
83
|
+
kind: "arithmetic",
|
|
84
|
+
op: "divide",
|
|
85
|
+
left: numberLiteral(1),
|
|
86
|
+
right: numberLiteral(0)
|
|
87
|
+
};
|
|
88
|
+
const wrongTypeArithmetic = {
|
|
89
|
+
kind: "arithmetic",
|
|
90
|
+
op: "add",
|
|
91
|
+
left: {
|
|
92
|
+
kind: "textLiteral",
|
|
93
|
+
value: "x"
|
|
94
|
+
},
|
|
95
|
+
right: numberLiteral(1)
|
|
96
|
+
};
|
|
97
|
+
const trueGuard = {
|
|
98
|
+
kind: "compare",
|
|
99
|
+
op: "eq",
|
|
100
|
+
left: numberLiteral(1),
|
|
101
|
+
right: numberLiteral(1)
|
|
102
|
+
};
|
|
103
|
+
const falseGuard = {
|
|
104
|
+
kind: "compare",
|
|
105
|
+
op: "eq",
|
|
106
|
+
left: numberLiteral(1),
|
|
107
|
+
right: numberLiteral(2)
|
|
108
|
+
};
|
|
109
|
+
const missingGuard = {
|
|
110
|
+
kind: "compare",
|
|
111
|
+
op: "eq",
|
|
112
|
+
left: missingRef,
|
|
113
|
+
right: numberLiteral(1)
|
|
114
|
+
};
|
|
115
|
+
/** Arbitrary non-`{-1,0,1,2}` magnitudes used below, named individually so each numeric literal only appears once (`@typescript-eslint/no-magic-numbers` only exempts -1/0/1/2 and object-literal property values, not values passed as plain call arguments). */
|
|
116
|
+
const memberOfProbeValue = 5;
|
|
117
|
+
const reduceInitialSeed = 5;
|
|
118
|
+
const laterConditionalCaseValue = 3;
|
|
119
|
+
const untouchedReduceInitial = 42;
|
|
120
|
+
const uniqueHitPolicyThirdCaseValue = 3;
|
|
121
|
+
const isDefinite = { status: "definite" };
|
|
122
|
+
const isNotFound = {
|
|
123
|
+
status: "indeterminate",
|
|
124
|
+
code: "not-found"
|
|
125
|
+
};
|
|
126
|
+
const isWrongType = {
|
|
127
|
+
status: "indeterminate",
|
|
128
|
+
code: "wrong-type"
|
|
129
|
+
};
|
|
130
|
+
const isDomainError = {
|
|
131
|
+
status: "indeterminate",
|
|
132
|
+
code: "domain-error"
|
|
133
|
+
};
|
|
134
|
+
function pred(description, node, expected, overrides = {}) {
|
|
135
|
+
const { context, resolvers = baseResolvers, functions } = overrides;
|
|
136
|
+
const { evaluatePredicate: evaluate } = functions ? createEvaluator({ functions }) : { evaluatePredicate };
|
|
137
|
+
return {
|
|
138
|
+
description,
|
|
139
|
+
expected,
|
|
140
|
+
run: async () => evaluate(node, context, resolvers)
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function expr(description, node, expected, overrides = {}) {
|
|
144
|
+
const { context, resolvers = baseResolvers, functions } = overrides;
|
|
145
|
+
const { evaluateValue: evaluate } = functions ? createEvaluator({ functions }) : { evaluateValue };
|
|
146
|
+
return {
|
|
147
|
+
description,
|
|
148
|
+
expected,
|
|
149
|
+
run: async () => evaluate(node, context, resolvers)
|
|
150
|
+
};
|
|
151
|
+
}
|
|
152
|
+
async function runFixture({ run, expected }) {
|
|
153
|
+
const result = await run();
|
|
154
|
+
globalExpect(result.status).toBe(expected.status);
|
|
155
|
+
if (expected.status === "indeterminate" && result.status === "indeterminate") globalExpect(result.reason.code).toBe(expected.code);
|
|
156
|
+
}
|
|
157
|
+
//#endregion
|
|
158
|
+
export { baseResolvers, divideByZero, expr, falseGuard, isDefinite, isDomainError, isNotFound, isPlainRecord, isUnknownArray, isWrongType, laterConditionalCaseValue, memberOfProbeValue, missingGuard, missingRef, numberLiteral, pred, reduceInitialSeed, runFixture, trueGuard, uniqueHitPolicyThirdCaseValue, untouchedReduceInitial, wrongTypeArithmetic };
|