@stigmer/eval-runtime 0.0.0-stage → 3.41.1-dev.20261011130052.g3d61c86c2a34
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/LICENSE +190 -0
- package/expect.d.ts +116 -0
- package/expect.d.ts.map +1 -0
- package/expect.js +363 -0
- package/expect.js.map +1 -0
- package/index.d.ts +5 -0
- package/index.d.ts.map +1 -0
- package/index.js +9 -0
- package/index.js.map +1 -0
- package/mock.d.ts +56 -0
- package/mock.d.ts.map +1 -0
- package/mock.js +167 -0
- package/mock.js.map +1 -0
- package/package.json +29 -4
- package/src/expect.ts +395 -0
- package/src/index.ts +33 -0
- package/src/mock.ts +176 -0
- package/src/transcript.ts +254 -0
- package/src/try-stop.ts +94 -0
- package/transcript.d.ts +84 -0
- package/transcript.d.ts.map +1 -0
- package/transcript.js +230 -0
- package/transcript.js.map +1 -0
- package/try-stop.d.ts +49 -0
- package/try-stop.d.ts.map +1 -0
- package/try-stop.js +84 -0
- package/try-stop.js.map +1 -0
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
Apache License
|
|
2
|
+
Version 2.0, January 2004
|
|
3
|
+
http://www.apache.org/licenses/
|
|
4
|
+
|
|
5
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
6
|
+
|
|
7
|
+
1. Definitions.
|
|
8
|
+
|
|
9
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
10
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
11
|
+
|
|
12
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
13
|
+
the copyright owner that is granting the License.
|
|
14
|
+
|
|
15
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
16
|
+
other entities that control, are controlled by, or are under common
|
|
17
|
+
control with that entity. For the purposes of this definition,
|
|
18
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
19
|
+
direction or management of such entity, whether by contract or
|
|
20
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
21
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
22
|
+
|
|
23
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
24
|
+
exercising permissions granted by this License.
|
|
25
|
+
|
|
26
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
27
|
+
including but not limited to software source code, documentation
|
|
28
|
+
source, and configuration files.
|
|
29
|
+
|
|
30
|
+
"Object" form shall mean any form resulting from mechanical
|
|
31
|
+
transformation or translation of a Source form, including but
|
|
32
|
+
not limited to compiled object code, generated documentation,
|
|
33
|
+
and conversions to other media types.
|
|
34
|
+
|
|
35
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
36
|
+
Object form, made available under the License, as indicated by a
|
|
37
|
+
copyright notice that is included in or attached to the work
|
|
38
|
+
(an example is provided in the Appendix below).
|
|
39
|
+
|
|
40
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
41
|
+
form, that is based on (or derived from) the Work and for which the
|
|
42
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
43
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
44
|
+
of this License, Derivative Works shall not include works that remain
|
|
45
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
46
|
+
the Work and Derivative Works thereof.
|
|
47
|
+
|
|
48
|
+
"Contribution" shall mean any work of authorship, including
|
|
49
|
+
the original version of the Work and any modifications or additions
|
|
50
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
51
|
+
submitted to Licensor for inclusion in the Work by the copyright owner
|
|
52
|
+
or by an individual or Legal Entity authorized to submit on behalf of
|
|
53
|
+
the copyright owner. For the purposes of this definition, "submitted"
|
|
54
|
+
means any form of electronic, verbal, or written communication sent
|
|
55
|
+
to the Licensor or its representatives, including but not limited to
|
|
56
|
+
communication on electronic mailing lists, source code control systems,
|
|
57
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
58
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
59
|
+
excluding communication that is conspicuously marked or otherwise
|
|
60
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
61
|
+
|
|
62
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
63
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
64
|
+
subsequently incorporated within the Work.
|
|
65
|
+
|
|
66
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
67
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
68
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
69
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
70
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
71
|
+
Work and such Derivative Works in Source or Object form.
|
|
72
|
+
|
|
73
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
74
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
75
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
76
|
+
(except as stated in this section) patent license to make, have made,
|
|
77
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
78
|
+
where such license applies only to those patent claims licensable
|
|
79
|
+
by such Contributor that are necessarily infringed by their
|
|
80
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
81
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
82
|
+
institute patent litigation against any entity (including a
|
|
83
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
84
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
85
|
+
or contributory patent infringement, then any patent licenses
|
|
86
|
+
granted to You under this License for that Work shall terminate
|
|
87
|
+
as of the date such litigation is filed.
|
|
88
|
+
|
|
89
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
90
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
91
|
+
modifications, and in Source or Object form, provided that You
|
|
92
|
+
meet the following conditions:
|
|
93
|
+
|
|
94
|
+
(a) You must give any other recipients of the Work or
|
|
95
|
+
Derivative Works a copy of this License; and
|
|
96
|
+
|
|
97
|
+
(b) You must cause any modified files to carry prominent notices
|
|
98
|
+
stating that You changed the files; and
|
|
99
|
+
|
|
100
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
101
|
+
that You distribute, all copyright, patent, trademark, and
|
|
102
|
+
attribution notices from the Source form of the Work,
|
|
103
|
+
excluding those notices that do not pertain to any part of
|
|
104
|
+
the Derivative Works; and
|
|
105
|
+
|
|
106
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
107
|
+
distribution, then any Derivative Works that You distribute must
|
|
108
|
+
include a readable copy of the attribution notices contained
|
|
109
|
+
within such NOTICE file, excluding those notices that do not
|
|
110
|
+
pertain to any part of the Derivative Works, in at least one
|
|
111
|
+
of the following places: within a NOTICE text file distributed
|
|
112
|
+
as part of the Derivative Works; within the Source form or
|
|
113
|
+
documentation, if provided along with the Derivative Works; or,
|
|
114
|
+
within a display generated by the Derivative Works, if and
|
|
115
|
+
wherever such third-party notices normally appear. The contents
|
|
116
|
+
of the NOTICE file are for informational purposes only and
|
|
117
|
+
do not modify the License. You may add Your own attribution
|
|
118
|
+
notices within Derivative Works that You distribute, alongside
|
|
119
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
120
|
+
that such additional attribution notices cannot be construed
|
|
121
|
+
as modifying the License.
|
|
122
|
+
|
|
123
|
+
You may add Your own copyright statement to Your modifications and
|
|
124
|
+
may provide additional or different license terms and conditions
|
|
125
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
126
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
127
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
128
|
+
the conditions stated in this License.
|
|
129
|
+
|
|
130
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
131
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
132
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
133
|
+
this License, without any additional terms or conditions.
|
|
134
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
135
|
+
the terms of any separate license agreement you may have executed
|
|
136
|
+
with Licensor regarding such Contributions.
|
|
137
|
+
|
|
138
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
139
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
140
|
+
except as required for reasonable and customary use in describing the
|
|
141
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
142
|
+
|
|
143
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
144
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
145
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
146
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
147
|
+
implied, including, without limitation, any warranties or conditions
|
|
148
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
149
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
150
|
+
appropriateness of using or redistributing the Work and assume any
|
|
151
|
+
risks associated with Your exercise of permissions under this License.
|
|
152
|
+
|
|
153
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
154
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
155
|
+
unless required by applicable law (such as deliberate and grossly
|
|
156
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
157
|
+
liable to You for damages, including any direct, indirect, special,
|
|
158
|
+
incidental, or consequential damages of any character arising as a
|
|
159
|
+
result of this License or out of the use or inability to use the
|
|
160
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
161
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
162
|
+
other commercial damages or losses), even if such Contributor
|
|
163
|
+
has been advised of the possibility of such damages.
|
|
164
|
+
|
|
165
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
166
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
167
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
168
|
+
or other liability obligations and/or rights consistent with this
|
|
169
|
+
License. However, in accepting such obligations, You may act only
|
|
170
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
171
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
172
|
+
defend, and hold each Contributor harmless for any liability
|
|
173
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
174
|
+
of your accepting any such warranty or additional liability.
|
|
175
|
+
|
|
176
|
+
END OF TERMS AND CONDITIONS
|
|
177
|
+
|
|
178
|
+
Copyright 2026 Stigmer Contributors
|
|
179
|
+
|
|
180
|
+
Licensed under the Apache License, Version 2.0 (the "License");
|
|
181
|
+
you may not use this file except in compliance with the License.
|
|
182
|
+
You may obtain a copy of the License at
|
|
183
|
+
|
|
184
|
+
http://www.apache.org/licenses/LICENSE-2.0
|
|
185
|
+
|
|
186
|
+
Unless required by applicable law or agreed to in writing, software
|
|
187
|
+
distributed under the License is distributed on an "AS IS" BASIS,
|
|
188
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
189
|
+
See the License for the specific language governing permissions and
|
|
190
|
+
limitations under the License.
|
package/expect.d.ts
ADDED
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A mock's `expect:` guard: what a call's input must look like, checked
|
|
3
|
+
* before the mock answers. A call that violates it stops the try.
|
|
4
|
+
*
|
|
5
|
+
* The guard is a map from dotted input paths (`issue.title`) to one rule:
|
|
6
|
+
* - a type name: `string`, `number`, `boolean`, `array` or `object`;
|
|
7
|
+
* - a `/regex/flags` string, in the format's small dialect (below);
|
|
8
|
+
* - any other string, number, boolean or null: the value must equal it;
|
|
9
|
+
* - a list of such literals: the value must equal one of them.
|
|
10
|
+
* A path the input does not carry is a violation.
|
|
11
|
+
*
|
|
12
|
+
* The regex dialect is the format's: literal characters, `.`, the escapes
|
|
13
|
+
* `\d \w \s \D \W \S` and an escaped punctuation character, classes such
|
|
14
|
+
* as `[a-z]` or `[^0-9]`, the quantifiers `*`, `+`, `?`, `{m}`, `{m,}` and
|
|
15
|
+
* `{m,n}` on one character, escape or class, an optional `^` first and `$`
|
|
16
|
+
* last, and the flags `i` and `s` only. Anything else (a group, an
|
|
17
|
+
* alternation, a backreference, a lookaround, another flag) is refused at
|
|
18
|
+
* compile with a sentence naming the pattern, which the suite reader turns
|
|
19
|
+
* into the case's load error.
|
|
20
|
+
*
|
|
21
|
+
* Matching is linear: the pattern is expanded into a sequence of units
|
|
22
|
+
* (a quantifier's minimum as required units, the rest optional, an
|
|
23
|
+
* unbounded tail as one repeating unit) and simulated as a set of
|
|
24
|
+
* positions over the value, so a value of length n costs n times the
|
|
25
|
+
* units, never a backtracking blow-up. The expansion is capped at
|
|
26
|
+
* EXPECT_MAX_UNITS, and a quantifier is sized against the cap before it is
|
|
27
|
+
* expanded, so a `{m,n}` cannot make a pattern large.
|
|
28
|
+
*
|
|
29
|
+
* Unlike Claude Code, a value is matched whole, whatever its length: the
|
|
30
|
+
* format bounds the length a pattern checks without documenting the bound,
|
|
31
|
+
* and the matcher here has no need for one. The guide states it.
|
|
32
|
+
*/
|
|
33
|
+
/** The type names a rule may give. */
|
|
34
|
+
declare const TYPE_NAMES: readonly ["string", "number", "boolean", "array", "object"];
|
|
35
|
+
type TypeName = (typeof TYPE_NAMES)[number];
|
|
36
|
+
/** The most units a pattern may expand to. */
|
|
37
|
+
export declare const EXPECT_MAX_UNITS = 1024;
|
|
38
|
+
/** The most characters a pattern may hold. */
|
|
39
|
+
export declare const EXPECT_MAX_PATTERN_LENGTH = 512;
|
|
40
|
+
/** One compiled rule of a guard. */
|
|
41
|
+
type Rule = {
|
|
42
|
+
readonly kind: "type";
|
|
43
|
+
readonly type: TypeName;
|
|
44
|
+
} | {
|
|
45
|
+
readonly kind: "regex";
|
|
46
|
+
readonly source: string;
|
|
47
|
+
readonly pattern: CompiledPattern;
|
|
48
|
+
} | {
|
|
49
|
+
readonly kind: "literal";
|
|
50
|
+
readonly value: Literal;
|
|
51
|
+
} | {
|
|
52
|
+
readonly kind: "one-of";
|
|
53
|
+
readonly values: readonly Literal[];
|
|
54
|
+
};
|
|
55
|
+
type Literal = string | number | boolean | null;
|
|
56
|
+
/** A compiled guard: each dotted path and its rule, in the order written. */
|
|
57
|
+
export interface CompiledExpect {
|
|
58
|
+
readonly rules: readonly {
|
|
59
|
+
readonly path: string;
|
|
60
|
+
readonly rule: Rule;
|
|
61
|
+
}[];
|
|
62
|
+
}
|
|
63
|
+
/** A compiled guard, or why the block is not one. */
|
|
64
|
+
export type ExpectCompile = {
|
|
65
|
+
readonly ok: true;
|
|
66
|
+
readonly expect: CompiledExpect;
|
|
67
|
+
} | {
|
|
68
|
+
readonly ok: false;
|
|
69
|
+
readonly error: string;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Compile an `expect:` block as parsed from YAML (or its JSON form, as a
|
|
73
|
+
* run carries it). Refuses a block that is not a map, a path that is not
|
|
74
|
+
* dotted names, and any rule outside the list in the module header.
|
|
75
|
+
*/
|
|
76
|
+
export declare function compileExpect(block: unknown): ExpectCompile;
|
|
77
|
+
/** Why `input` violates the guard, as one sentence; `undefined` when it holds. */
|
|
78
|
+
export declare function checkExpect(expect: CompiledExpect, input: unknown): string | undefined;
|
|
79
|
+
/** What one unit consumes: one character. */
|
|
80
|
+
type Atom = {
|
|
81
|
+
readonly kind: "char";
|
|
82
|
+
readonly char: string;
|
|
83
|
+
} | {
|
|
84
|
+
readonly kind: "any";
|
|
85
|
+
} | {
|
|
86
|
+
readonly kind: "class";
|
|
87
|
+
readonly negated: boolean;
|
|
88
|
+
readonly items: readonly ClassItem[];
|
|
89
|
+
};
|
|
90
|
+
type ClassItem = {
|
|
91
|
+
readonly kind: "range";
|
|
92
|
+
readonly from: number;
|
|
93
|
+
readonly to: number;
|
|
94
|
+
} | {
|
|
95
|
+
readonly kind: "escape";
|
|
96
|
+
readonly letter: string;
|
|
97
|
+
};
|
|
98
|
+
/** One step of the expanded pattern: required, optional, or repeating any number of times. */
|
|
99
|
+
interface Unit {
|
|
100
|
+
readonly atom: Atom;
|
|
101
|
+
readonly mode: "one" | "optional" | "star";
|
|
102
|
+
}
|
|
103
|
+
/** A pattern compiled for {@link matchPattern}. */
|
|
104
|
+
export interface CompiledPattern {
|
|
105
|
+
readonly units: readonly Unit[];
|
|
106
|
+
readonly anchoredStart: boolean;
|
|
107
|
+
readonly anchoredEnd: boolean;
|
|
108
|
+
readonly ignoreCase: boolean;
|
|
109
|
+
readonly dotAll: boolean;
|
|
110
|
+
}
|
|
111
|
+
/** Compile a pattern in the dialect, or say why it is outside it. */
|
|
112
|
+
export declare function compilePattern(source: string, flags: string): CompiledPattern | string;
|
|
113
|
+
/** Whether `pattern` is found in `value` (anywhere, unless anchored). */
|
|
114
|
+
export declare function matchPattern(pattern: CompiledPattern, value: string): boolean;
|
|
115
|
+
export {};
|
|
116
|
+
//# sourceMappingURL=expect.d.ts.map
|
package/expect.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"expect.d.ts","sourceRoot":"","sources":["src/expect.ts"],"names":[],"mappings":"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"}
|
package/expect.js
ADDED
|
@@ -0,0 +1,363 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A mock's `expect:` guard: what a call's input must look like, checked
|
|
3
|
+
* before the mock answers. A call that violates it stops the try.
|
|
4
|
+
*
|
|
5
|
+
* The guard is a map from dotted input paths (`issue.title`) to one rule:
|
|
6
|
+
* - a type name: `string`, `number`, `boolean`, `array` or `object`;
|
|
7
|
+
* - a `/regex/flags` string, in the format's small dialect (below);
|
|
8
|
+
* - any other string, number, boolean or null: the value must equal it;
|
|
9
|
+
* - a list of such literals: the value must equal one of them.
|
|
10
|
+
* A path the input does not carry is a violation.
|
|
11
|
+
*
|
|
12
|
+
* The regex dialect is the format's: literal characters, `.`, the escapes
|
|
13
|
+
* `\d \w \s \D \W \S` and an escaped punctuation character, classes such
|
|
14
|
+
* as `[a-z]` or `[^0-9]`, the quantifiers `*`, `+`, `?`, `{m}`, `{m,}` and
|
|
15
|
+
* `{m,n}` on one character, escape or class, an optional `^` first and `$`
|
|
16
|
+
* last, and the flags `i` and `s` only. Anything else (a group, an
|
|
17
|
+
* alternation, a backreference, a lookaround, another flag) is refused at
|
|
18
|
+
* compile with a sentence naming the pattern, which the suite reader turns
|
|
19
|
+
* into the case's load error.
|
|
20
|
+
*
|
|
21
|
+
* Matching is linear: the pattern is expanded into a sequence of units
|
|
22
|
+
* (a quantifier's minimum as required units, the rest optional, an
|
|
23
|
+
* unbounded tail as one repeating unit) and simulated as a set of
|
|
24
|
+
* positions over the value, so a value of length n costs n times the
|
|
25
|
+
* units, never a backtracking blow-up. The expansion is capped at
|
|
26
|
+
* EXPECT_MAX_UNITS, and a quantifier is sized against the cap before it is
|
|
27
|
+
* expanded, so a `{m,n}` cannot make a pattern large.
|
|
28
|
+
*
|
|
29
|
+
* Unlike Claude Code, a value is matched whole, whatever its length: the
|
|
30
|
+
* format bounds the length a pattern checks without documenting the bound,
|
|
31
|
+
* and the matcher here has no need for one. The guide states it.
|
|
32
|
+
*/
|
|
33
|
+
/** The type names a rule may give. */
|
|
34
|
+
const TYPE_NAMES = ["string", "number", "boolean", "array", "object"];
|
|
35
|
+
/** The most units a pattern may expand to. */
|
|
36
|
+
export const EXPECT_MAX_UNITS = 1024;
|
|
37
|
+
/** The most characters a pattern may hold. */
|
|
38
|
+
export const EXPECT_MAX_PATTERN_LENGTH = 512;
|
|
39
|
+
/**
|
|
40
|
+
* Compile an `expect:` block as parsed from YAML (or its JSON form, as a
|
|
41
|
+
* run carries it). Refuses a block that is not a map, a path that is not
|
|
42
|
+
* dotted names, and any rule outside the list in the module header.
|
|
43
|
+
*/
|
|
44
|
+
export function compileExpect(block) {
|
|
45
|
+
if (!isRecord(block))
|
|
46
|
+
return { ok: false, error: "expect must be a map from input paths to rules" };
|
|
47
|
+
const rules = [];
|
|
48
|
+
for (const [path, value] of Object.entries(block)) {
|
|
49
|
+
if (!/^[A-Za-z0-9_-]+(\.[A-Za-z0-9_-]+)*$/.test(path)) {
|
|
50
|
+
return { ok: false, error: `expect path '${path}' is not a dotted input path` };
|
|
51
|
+
}
|
|
52
|
+
const rule = ruleOf(value);
|
|
53
|
+
if (typeof rule === "string")
|
|
54
|
+
return { ok: false, error: `expect.${path}: ${rule}` };
|
|
55
|
+
rules.push({ path, rule });
|
|
56
|
+
}
|
|
57
|
+
return { ok: true, expect: { rules } };
|
|
58
|
+
}
|
|
59
|
+
/** Why `input` violates the guard, as one sentence; `undefined` when it holds. */
|
|
60
|
+
export function checkExpect(expect, input) {
|
|
61
|
+
for (const { path, rule } of expect.rules) {
|
|
62
|
+
const found = valueAt(input, path);
|
|
63
|
+
if (!found.present)
|
|
64
|
+
return `input.${path} is missing`;
|
|
65
|
+
const violation = violationOf(rule, found.value);
|
|
66
|
+
if (violation !== undefined)
|
|
67
|
+
return `input.${path} ${violation}`;
|
|
68
|
+
}
|
|
69
|
+
return undefined;
|
|
70
|
+
}
|
|
71
|
+
function ruleOf(value) {
|
|
72
|
+
if (Array.isArray(value)) {
|
|
73
|
+
const values = [];
|
|
74
|
+
for (const item of value) {
|
|
75
|
+
if (!isLiteral(item))
|
|
76
|
+
return "a list must hold literals only";
|
|
77
|
+
values.push(item);
|
|
78
|
+
}
|
|
79
|
+
if (values.length === 0)
|
|
80
|
+
return "a list must name at least one value";
|
|
81
|
+
return { kind: "one-of", values };
|
|
82
|
+
}
|
|
83
|
+
if (typeof value === "string") {
|
|
84
|
+
if (TYPE_NAMES.includes(value))
|
|
85
|
+
return { kind: "type", type: value };
|
|
86
|
+
const regex = /^\/(.*)\/([a-z]*)$/s.exec(value);
|
|
87
|
+
if (regex !== null) {
|
|
88
|
+
const compiled = compilePattern(regex[1] ?? "", regex[2] ?? "");
|
|
89
|
+
if (typeof compiled === "string")
|
|
90
|
+
return `the pattern ${value} ${compiled}`;
|
|
91
|
+
return { kind: "regex", source: value, pattern: compiled };
|
|
92
|
+
}
|
|
93
|
+
return { kind: "literal", value };
|
|
94
|
+
}
|
|
95
|
+
if (isLiteral(value))
|
|
96
|
+
return { kind: "literal", value };
|
|
97
|
+
return "a rule must be a type name, a /regex/, a literal or a list of literals";
|
|
98
|
+
}
|
|
99
|
+
function violationOf(rule, value) {
|
|
100
|
+
switch (rule.kind) {
|
|
101
|
+
case "type":
|
|
102
|
+
return typeOf(value) === rule.type ? undefined : `must be ${article(rule.type)}`;
|
|
103
|
+
case "regex":
|
|
104
|
+
return matchPattern(rule.pattern, textOf(value)) ? undefined : `must match ${rule.source}`;
|
|
105
|
+
case "literal":
|
|
106
|
+
return value === rule.value ? undefined : `must be ${JSON.stringify(rule.value)}`;
|
|
107
|
+
case "one-of":
|
|
108
|
+
return rule.values.some((v) => v === value)
|
|
109
|
+
? undefined
|
|
110
|
+
: `must be one of ${rule.values.map((v) => (typeof v === "string" ? v : JSON.stringify(v))).join(", ")}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
function typeOf(value) {
|
|
114
|
+
if (Array.isArray(value))
|
|
115
|
+
return "array";
|
|
116
|
+
if (value === null)
|
|
117
|
+
return "null";
|
|
118
|
+
return typeof value;
|
|
119
|
+
}
|
|
120
|
+
function article(type) {
|
|
121
|
+
return type === "array" || type === "object" ? `an ${type}` : `a ${type}`;
|
|
122
|
+
}
|
|
123
|
+
function textOf(value) {
|
|
124
|
+
return typeof value === "string" ? value : JSON.stringify(value) ?? "";
|
|
125
|
+
}
|
|
126
|
+
function valueAt(input, path) {
|
|
127
|
+
let current = input;
|
|
128
|
+
for (const key of path.split(".")) {
|
|
129
|
+
if (!isRecord(current) || !Object.hasOwn(current, key))
|
|
130
|
+
return { present: false };
|
|
131
|
+
current = current[key];
|
|
132
|
+
}
|
|
133
|
+
return { present: true, value: current };
|
|
134
|
+
}
|
|
135
|
+
/** Compile a pattern in the dialect, or say why it is outside it. */
|
|
136
|
+
export function compilePattern(source, flags) {
|
|
137
|
+
if ([...flags].some((f) => f !== "i" && f !== "s") || new Set(flags).size !== flags.length) {
|
|
138
|
+
return `uses a flag other than i and s`;
|
|
139
|
+
}
|
|
140
|
+
if (source.length > EXPECT_MAX_PATTERN_LENGTH) {
|
|
141
|
+
return `is longer than ${EXPECT_MAX_PATTERN_LENGTH} characters`;
|
|
142
|
+
}
|
|
143
|
+
const chars = [...source];
|
|
144
|
+
let i = 0;
|
|
145
|
+
const anchoredStart = chars[0] === "^";
|
|
146
|
+
if (anchoredStart)
|
|
147
|
+
i = 1;
|
|
148
|
+
let end = chars.length;
|
|
149
|
+
const anchoredEnd = end > i && chars[end - 1] === "$" && !escapedAt(chars, end - 1);
|
|
150
|
+
if (anchoredEnd)
|
|
151
|
+
end -= 1;
|
|
152
|
+
const units = [];
|
|
153
|
+
while (i < end) {
|
|
154
|
+
const read = atomAt(chars, i, end);
|
|
155
|
+
if (typeof read === "string")
|
|
156
|
+
return read;
|
|
157
|
+
i = read.next;
|
|
158
|
+
const quantifier = quantifierAt(chars, i, end);
|
|
159
|
+
if (typeof quantifier === "string")
|
|
160
|
+
return quantifier;
|
|
161
|
+
i = quantifier.next;
|
|
162
|
+
// Sized before it is expanded: a {m,n} of millions must be refused, not built.
|
|
163
|
+
const adds = quantifier.min + (quantifier.max === Infinity ? 1 : quantifier.max - quantifier.min);
|
|
164
|
+
if (units.length + adds > EXPECT_MAX_UNITS)
|
|
165
|
+
return `expands to more than ${EXPECT_MAX_UNITS} steps`;
|
|
166
|
+
for (let n = 0; n < quantifier.min; n++)
|
|
167
|
+
units.push({ atom: read.atom, mode: "one" });
|
|
168
|
+
if (quantifier.max === Infinity) {
|
|
169
|
+
units.push({ atom: read.atom, mode: "star" });
|
|
170
|
+
}
|
|
171
|
+
else {
|
|
172
|
+
for (let n = quantifier.min; n < quantifier.max; n++)
|
|
173
|
+
units.push({ atom: read.atom, mode: "optional" });
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return { units, anchoredStart, anchoredEnd, ignoreCase: flags.includes("i"), dotAll: flags.includes("s") };
|
|
177
|
+
}
|
|
178
|
+
function escapedAt(chars, index) {
|
|
179
|
+
let slashes = 0;
|
|
180
|
+
for (let j = index - 1; j >= 0 && chars[j] === "\\"; j--)
|
|
181
|
+
slashes++;
|
|
182
|
+
return slashes % 2 === 1;
|
|
183
|
+
}
|
|
184
|
+
const ESCAPE_CLASSES = new Set(["d", "w", "s", "D", "W", "S"]);
|
|
185
|
+
const SPECIALS = new Set(["(", ")", "|", "{", "}", "*", "+", "?", "^", "$"]);
|
|
186
|
+
function atomAt(chars, i, end) {
|
|
187
|
+
const c = chars[i] ?? "";
|
|
188
|
+
if (c === "\\") {
|
|
189
|
+
const e = chars[i + 1];
|
|
190
|
+
if (e === undefined || i + 1 >= end)
|
|
191
|
+
return "ends with a lone backslash";
|
|
192
|
+
if (ESCAPE_CLASSES.has(e))
|
|
193
|
+
return { atom: { kind: "class", negated: false, items: [{ kind: "escape", letter: e }] }, next: i + 2 };
|
|
194
|
+
if (/^[^A-Za-z0-9]$/.test(e))
|
|
195
|
+
return { atom: { kind: "char", char: e }, next: i + 2 };
|
|
196
|
+
if (e === "n")
|
|
197
|
+
return { atom: { kind: "char", char: "\n" }, next: i + 2 };
|
|
198
|
+
if (e === "t")
|
|
199
|
+
return { atom: { kind: "char", char: "\t" }, next: i + 2 };
|
|
200
|
+
return `uses the escape \\${e}, which the dialect does not have`;
|
|
201
|
+
}
|
|
202
|
+
if (c === "[")
|
|
203
|
+
return classAt(chars, i, end);
|
|
204
|
+
if (c === ".")
|
|
205
|
+
return { atom: { kind: "any" }, next: i + 1 };
|
|
206
|
+
if (c === "(" || c === ")")
|
|
207
|
+
return "uses a group";
|
|
208
|
+
if (c === "|")
|
|
209
|
+
return "uses an alternation";
|
|
210
|
+
if (SPECIALS.has(c))
|
|
211
|
+
return `has a ${c} with nothing to apply to`;
|
|
212
|
+
return { atom: { kind: "char", char: c }, next: i + 1 };
|
|
213
|
+
}
|
|
214
|
+
function classAt(chars, start, end) {
|
|
215
|
+
let i = start + 1;
|
|
216
|
+
const negated = chars[i] === "^";
|
|
217
|
+
if (negated)
|
|
218
|
+
i++;
|
|
219
|
+
const items = [];
|
|
220
|
+
let first = true;
|
|
221
|
+
while (i < end) {
|
|
222
|
+
const c = chars[i] ?? "";
|
|
223
|
+
if (c === "]" && !first)
|
|
224
|
+
return { atom: { kind: "class", negated, items }, next: i + 1 };
|
|
225
|
+
first = false;
|
|
226
|
+
let from;
|
|
227
|
+
if (c === "\\") {
|
|
228
|
+
const e = chars[i + 1];
|
|
229
|
+
if (e === undefined || i + 1 >= end)
|
|
230
|
+
return "has a class that never closes";
|
|
231
|
+
if (ESCAPE_CLASSES.has(e)) {
|
|
232
|
+
items.push({ kind: "escape", letter: e });
|
|
233
|
+
i += 2;
|
|
234
|
+
continue;
|
|
235
|
+
}
|
|
236
|
+
from = (e === "n" ? "\n" : e === "t" ? "\t" : e).codePointAt(0) ?? 0;
|
|
237
|
+
i += 2;
|
|
238
|
+
}
|
|
239
|
+
else {
|
|
240
|
+
from = c.codePointAt(0) ?? 0;
|
|
241
|
+
i += 1;
|
|
242
|
+
}
|
|
243
|
+
if (chars[i] === "-" && i + 1 < end && chars[i + 1] !== "]") {
|
|
244
|
+
const t = chars[i + 1] ?? "";
|
|
245
|
+
const to = (t === "\\" ? (chars[i + 2] ?? "") : t).codePointAt(0) ?? 0;
|
|
246
|
+
if (to < from)
|
|
247
|
+
return "has a reversed range in a class";
|
|
248
|
+
items.push({ kind: "range", from, to });
|
|
249
|
+
i += t === "\\" ? 3 : 2;
|
|
250
|
+
}
|
|
251
|
+
else {
|
|
252
|
+
items.push({ kind: "range", from, to: from });
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return "has a class that never closes";
|
|
256
|
+
}
|
|
257
|
+
function quantifierAt(chars, i, end) {
|
|
258
|
+
const c = chars[i];
|
|
259
|
+
let read = { min: 1, max: 1, next: i };
|
|
260
|
+
if (i < end && c === "*")
|
|
261
|
+
read = { min: 0, max: Infinity, next: i + 1 };
|
|
262
|
+
else if (i < end && c === "+")
|
|
263
|
+
read = { min: 1, max: Infinity, next: i + 1 };
|
|
264
|
+
else if (i < end && c === "?")
|
|
265
|
+
read = { min: 0, max: 1, next: i + 1 };
|
|
266
|
+
else if (i < end && c === "{") {
|
|
267
|
+
let j = i + 1;
|
|
268
|
+
let body = "";
|
|
269
|
+
while (j < end && chars[j] !== "}")
|
|
270
|
+
body += chars[j++];
|
|
271
|
+
const m = /^(\d+)(,(\d*))?$/.exec(body);
|
|
272
|
+
if (j >= end || m === null)
|
|
273
|
+
return "has a { that is not a {m,n} quantifier";
|
|
274
|
+
const min = Number(m[1]);
|
|
275
|
+
const max = m[2] === undefined ? min : m[3] === "" ? Infinity : Number(m[3]);
|
|
276
|
+
if (max < min)
|
|
277
|
+
return "has a {m,n} quantifier whose n is below its m";
|
|
278
|
+
read = { min, max, next: j + 1 };
|
|
279
|
+
}
|
|
280
|
+
const after = chars[read.next];
|
|
281
|
+
if (read.next < end && read.next !== i && (after === "*" || after === "+" || after === "?" || after === "{")) {
|
|
282
|
+
return "quantifies a quantifier";
|
|
283
|
+
}
|
|
284
|
+
return read;
|
|
285
|
+
}
|
|
286
|
+
/** Whether `pattern` is found in `value` (anywhere, unless anchored). */
|
|
287
|
+
export function matchPattern(pattern, value) {
|
|
288
|
+
const text = [...value];
|
|
289
|
+
const n = pattern.units.length;
|
|
290
|
+
let states = closure(new Set([0]), pattern.units);
|
|
291
|
+
for (let pos = 0; pos <= text.length; pos++) {
|
|
292
|
+
if (states.has(n) && (!pattern.anchoredEnd || pos === text.length))
|
|
293
|
+
return true;
|
|
294
|
+
if (pos === text.length)
|
|
295
|
+
break;
|
|
296
|
+
const c = text[pos] ?? "";
|
|
297
|
+
const next = new Set();
|
|
298
|
+
for (const s of states) {
|
|
299
|
+
const unit = pattern.units[s];
|
|
300
|
+
if (unit === undefined || !atomMatches(unit.atom, c, pattern))
|
|
301
|
+
continue;
|
|
302
|
+
next.add(unit.mode === "star" ? s : s + 1);
|
|
303
|
+
}
|
|
304
|
+
if (!pattern.anchoredStart)
|
|
305
|
+
next.add(0);
|
|
306
|
+
states = closure(next, pattern.units);
|
|
307
|
+
if (states.size === 0)
|
|
308
|
+
return false;
|
|
309
|
+
}
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* States reachable by skipping optional and repeating units. A walk stops
|
|
314
|
+
* at a state already reached, since everything past it was reached with
|
|
315
|
+
* it, so one closure visits each state once and a step costs at most the
|
|
316
|
+
* pattern's units.
|
|
317
|
+
*/
|
|
318
|
+
function closure(states, units) {
|
|
319
|
+
const out = new Set();
|
|
320
|
+
for (const start of states) {
|
|
321
|
+
let s = start;
|
|
322
|
+
if (out.has(s))
|
|
323
|
+
continue;
|
|
324
|
+
out.add(s);
|
|
325
|
+
while (s < units.length && units[s]?.mode !== "one") {
|
|
326
|
+
s += 1;
|
|
327
|
+
if (out.has(s))
|
|
328
|
+
break;
|
|
329
|
+
out.add(s);
|
|
330
|
+
}
|
|
331
|
+
}
|
|
332
|
+
return out;
|
|
333
|
+
}
|
|
334
|
+
function atomMatches(atom, c, pattern) {
|
|
335
|
+
switch (atom.kind) {
|
|
336
|
+
case "any":
|
|
337
|
+
return pattern.dotAll || (c !== "\n" && c !== "\r");
|
|
338
|
+
case "char":
|
|
339
|
+
return pattern.ignoreCase ? c.toLowerCase() === atom.char.toLowerCase() : c === atom.char;
|
|
340
|
+
case "class": {
|
|
341
|
+
const hit = atom.items.some((item) => classItemMatches(item, c, pattern.ignoreCase));
|
|
342
|
+
return atom.negated ? !hit : hit;
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
function classItemMatches(item, c, ignoreCase) {
|
|
347
|
+
if (item.kind === "escape") {
|
|
348
|
+
const hit = item.letter.toLowerCase() === "d" ? /\d/.test(c) : item.letter.toLowerCase() === "w" ? /\w/.test(c) : /\s/.test(c);
|
|
349
|
+
return item.letter === item.letter.toUpperCase() ? !hit : hit;
|
|
350
|
+
}
|
|
351
|
+
const inRange = (ch) => {
|
|
352
|
+
const code = ch.codePointAt(0) ?? -1;
|
|
353
|
+
return code >= item.from && code <= item.to;
|
|
354
|
+
};
|
|
355
|
+
return inRange(c) || (ignoreCase && (inRange(c.toLowerCase()) || inRange(c.toUpperCase())));
|
|
356
|
+
}
|
|
357
|
+
function isLiteral(value) {
|
|
358
|
+
return value === null || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
|
|
359
|
+
}
|
|
360
|
+
function isRecord(value) {
|
|
361
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
362
|
+
}
|
|
363
|
+
//# sourceMappingURL=expect.js.map
|