@autometa/cucumber-expressions 0.4.4 → 1.0.0-rc.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/README.md +1 -1
- package/dist/extensions.d.ts +9 -0
- package/dist/index.cjs +317 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.ts +5 -104
- package/dist/index.js +279 -552
- package/dist/index.js.map +1 -1
- package/dist/parameter-types.d.ts +31 -0
- package/dist/types.d.ts +18 -0
- package/package.json +37 -34
- package/.eslintignore +0 -3
- package/.eslintrc.cjs +0 -4
- package/.turbo/turbo-coverage.log +0 -45
- package/.turbo/turbo-lint$colon$fix.log +0 -4
- package/.turbo/turbo-prettify.log +0 -0
- package/.turbo/turbo-test.log +0 -50
- package/CHANGELOG.md +0 -234
- package/dist/esm/index.js +0 -538
- package/dist/esm/index.js.map +0 -1
- package/dist/index.d.cts +0 -104
- package/tsup.config.ts +0 -14
package/dist/index.js
CHANGED
|
@@ -1,582 +1,309 @@
|
|
|
1
|
-
|
|
2
|
-
var __create = Object.create;
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
-
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
-
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
-
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
-
var __export = (target, all) => {
|
|
9
|
-
for (var name in all)
|
|
10
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
11
|
-
};
|
|
12
|
-
var __copyProps = (to, from, except, desc) => {
|
|
13
|
-
if (from && typeof from === "object" || typeof from === "function") {
|
|
14
|
-
for (let key of __getOwnPropNames(from))
|
|
15
|
-
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
16
|
-
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
17
|
-
}
|
|
18
|
-
return to;
|
|
19
|
-
};
|
|
20
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
-
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
-
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
-
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
-
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
-
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
-
mod
|
|
27
|
-
));
|
|
28
|
-
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
29
|
-
var __accessCheck = (obj, member, msg) => {
|
|
30
|
-
if (!member.has(obj))
|
|
31
|
-
throw TypeError("Cannot " + msg);
|
|
32
|
-
};
|
|
33
|
-
var __privateGet = (obj, member, getter) => {
|
|
34
|
-
__accessCheck(obj, member, "read from private field");
|
|
35
|
-
return getter ? getter.call(obj) : member.get(obj);
|
|
36
|
-
};
|
|
37
|
-
var __privateAdd = (obj, member, value) => {
|
|
38
|
-
if (member.has(obj))
|
|
39
|
-
throw TypeError("Cannot add the same private member more than once");
|
|
40
|
-
member instanceof WeakSet ? member.add(obj) : member.set(obj, value);
|
|
41
|
-
};
|
|
42
|
-
|
|
43
|
-
// src/index.ts
|
|
44
|
-
var src_exports = {};
|
|
45
|
-
__export(src_exports, {
|
|
46
|
-
AnyParam: () => AnyParam,
|
|
47
|
-
BoolParam: () => BoolParam,
|
|
48
|
-
BooleanParam: () => BooleanParam,
|
|
49
|
-
DateParam: () => DateParam,
|
|
50
|
-
DifferentStepTypeMatch: () => DifferentStepTypeMatch,
|
|
51
|
-
FuzzySearchReport: () => FuzzySearchReport,
|
|
52
|
-
NumberParam: () => NumberParam,
|
|
53
|
-
OrdinalParam: () => OrdinalParam,
|
|
54
|
-
PrimitiveParam: () => PrimitiveParam,
|
|
55
|
-
SameStepTypeMatch: () => SameStepTypeMatch,
|
|
56
|
-
TextParam: () => TextParam,
|
|
57
|
-
UnknownParam: () => UnknownParam,
|
|
58
|
-
buildFuzzySearchReport: () => buildFuzzySearchReport,
|
|
59
|
-
checkMatch: () => checkMatch,
|
|
60
|
-
defineParameterType: () => defineParameterType,
|
|
61
|
-
getDiff: () => getDiff,
|
|
62
|
-
getDiffs: () => getDiffs,
|
|
63
|
-
isExpressionCandidate: () => isExpressionCandidate,
|
|
64
|
-
limitDiffs: () => limitDiffs,
|
|
65
|
-
refineDiff: () => refineDiff
|
|
66
|
-
});
|
|
67
|
-
module.exports = __toCommonJS(src_exports);
|
|
1
|
+
import { ParameterType, Argument } from '@cucumber/cucumber-expressions';
|
|
68
2
|
|
|
69
|
-
// src/
|
|
70
|
-
var
|
|
71
|
-
var
|
|
72
|
-
|
|
73
|
-
|
|
3
|
+
// src/parameter-types.ts
|
|
4
|
+
var transformSymbol = Symbol("autometa:cucumber:transform");
|
|
5
|
+
var extensionsApplied = false;
|
|
6
|
+
var originalTransform;
|
|
7
|
+
var originalGetValue;
|
|
8
|
+
function attachTransform(parameterType, transform) {
|
|
9
|
+
parameterType[transformSymbol] = transform;
|
|
74
10
|
}
|
|
75
|
-
function
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
const otherStepDistance = differentStepType.map((it) => it.distance);
|
|
79
|
-
const minDifferentStepDistance = Math.min(...otherStepDistance);
|
|
80
|
-
if (maxSameStepDistance > minDifferentStepDistance) {
|
|
81
|
-
const filter = sameStepType.filter(
|
|
82
|
-
(it) => it.distance <= minDifferentStepDistance
|
|
83
|
-
);
|
|
84
|
-
if (filter.length >= max) {
|
|
85
|
-
return { same: filter.slice(0, max), other: [] };
|
|
86
|
-
}
|
|
87
|
-
const diff = max - filter.length;
|
|
88
|
-
const sameSlice = sameStepType.slice(0, diff);
|
|
89
|
-
const differentSlice = differentStepType.slice(0, max - diff);
|
|
90
|
-
return { same: sameSlice, other: differentSlice };
|
|
91
|
-
}
|
|
92
|
-
const maxIndex = Math.min(max, sameStepType.length);
|
|
93
|
-
return { same: sameStepType.slice(0, maxIndex), other: [] };
|
|
94
|
-
}
|
|
95
|
-
function removeWhitespaceFromQuotedSubstrings(inputString) {
|
|
96
|
-
const regex = /(["'])([^"']*?)\1/g;
|
|
97
|
-
let modifiedString = inputString;
|
|
98
|
-
let match;
|
|
99
|
-
while (match = regex.exec(inputString)) {
|
|
100
|
-
const quotedSubstring = match[0];
|
|
101
|
-
const strippedSubstring = match[2].replace(/\s+/g, "");
|
|
102
|
-
modifiedString = modifiedString.replace(
|
|
103
|
-
quotedSubstring,
|
|
104
|
-
`${match[1]}${strippedSubstring}${match[1]}`
|
|
105
|
-
);
|
|
11
|
+
function applyCucumberExtensions() {
|
|
12
|
+
if (extensionsApplied) {
|
|
13
|
+
return;
|
|
106
14
|
}
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
15
|
+
originalTransform = originalTransform ?? ParameterType.prototype.transform;
|
|
16
|
+
ParameterType.prototype.transform = function transform(thisObj, groupValues) {
|
|
17
|
+
const transformFn = this[transformSymbol];
|
|
18
|
+
if (transformFn) {
|
|
19
|
+
return transformFn(groupValues ?? null, {
|
|
20
|
+
world: thisObj,
|
|
21
|
+
parameterType: this
|
|
22
|
+
});
|
|
113
23
|
}
|
|
114
|
-
const
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
return
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
strings.push(gherkinChange.value);
|
|
133
|
-
const extra = extractTextAfterPlaceholder(scopeChange.value);
|
|
134
|
-
if (extra) {
|
|
135
|
-
strings.push(extra);
|
|
24
|
+
const normalized = groupValues ? [...groupValues] : [];
|
|
25
|
+
if (!originalTransform) {
|
|
26
|
+
throw new Error("Cucumber extensions have not been initialised correctly");
|
|
27
|
+
}
|
|
28
|
+
return originalTransform.call(this, thisObj, normalized);
|
|
29
|
+
};
|
|
30
|
+
originalGetValue = originalGetValue ?? Argument.prototype.getValue;
|
|
31
|
+
Argument.prototype.getValue = function getValue(context) {
|
|
32
|
+
const group = this.group;
|
|
33
|
+
let values = null;
|
|
34
|
+
if (group) {
|
|
35
|
+
const childValues = group.children?.map((child) => child.value).filter((value) => value !== void 0);
|
|
36
|
+
if (childValues && childValues.length > 0) {
|
|
37
|
+
values = childValues;
|
|
38
|
+
} else if (group.value !== void 0 && group.value !== null) {
|
|
39
|
+
values = [group.value];
|
|
40
|
+
} else if (group.values) {
|
|
41
|
+
values = group.values;
|
|
136
42
|
}
|
|
137
|
-
index++;
|
|
138
|
-
continue;
|
|
139
43
|
}
|
|
140
|
-
|
|
141
|
-
|
|
44
|
+
const parameterType = this.parameterType;
|
|
45
|
+
const transformFn = parameterType?.[transformSymbol];
|
|
46
|
+
if (transformFn && parameterType) {
|
|
47
|
+
return transformFn(values, {
|
|
48
|
+
world: context,
|
|
49
|
+
parameterType
|
|
50
|
+
});
|
|
142
51
|
}
|
|
143
|
-
if (
|
|
144
|
-
|
|
145
|
-
continue;
|
|
52
|
+
if (!originalGetValue) {
|
|
53
|
+
throw new Error("Cucumber extensions have not been initialised correctly");
|
|
146
54
|
}
|
|
147
|
-
|
|
148
|
-
|
|
55
|
+
return originalGetValue.call(this, context);
|
|
56
|
+
};
|
|
57
|
+
extensionsApplied = true;
|
|
149
58
|
}
|
|
150
|
-
function
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if (match && match[1]) {
|
|
154
|
-
return match[1];
|
|
155
|
-
} else {
|
|
156
|
-
return null;
|
|
59
|
+
function resetCucumberExtensions() {
|
|
60
|
+
if (!extensionsApplied) {
|
|
61
|
+
return;
|
|
157
62
|
}
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
if (change1 && change1.removed && change2 && change2.added) {
|
|
161
|
-
const scopeText = change2.value;
|
|
162
|
-
return /{.*}/.test(scopeText);
|
|
63
|
+
if (originalTransform) {
|
|
64
|
+
ParameterType.prototype.transform = originalTransform;
|
|
163
65
|
}
|
|
164
|
-
|
|
66
|
+
if (originalGetValue) {
|
|
67
|
+
Argument.prototype.getValue = originalGetValue;
|
|
68
|
+
}
|
|
69
|
+
extensionsApplied = false;
|
|
165
70
|
}
|
|
166
71
|
|
|
167
|
-
// src/
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
this.distance = diff.distance;
|
|
175
|
-
}
|
|
176
|
-
toString() {
|
|
177
|
-
const keyword = import_colors_cli.default.green(this.keyword);
|
|
178
|
-
const text = import_colors_cli.default.white(this.source);
|
|
179
|
-
const distance2 = import_colors_cli.default.blue(`[${this.distance}]`);
|
|
180
|
-
return `${distance2} ${keyword} ${text}`;
|
|
181
|
-
}
|
|
182
|
-
};
|
|
183
|
-
var DifferentStepTypeMatch = class {
|
|
184
|
-
constructor(diff) {
|
|
185
|
-
this.keyword = diff.step.keyword;
|
|
186
|
-
this.text = diff.merged;
|
|
187
|
-
this.source = diff.step.expression.source;
|
|
188
|
-
this.distance = diff.distance;
|
|
189
|
-
}
|
|
190
|
-
toString() {
|
|
191
|
-
const keywordColor = import_colors_cli.default.cyan_bt;
|
|
192
|
-
const keyword = keywordColor(this.keyword);
|
|
193
|
-
const text = import_colors_cli.default.white(this.source);
|
|
194
|
-
const distance2 = import_colors_cli.default.blue(`[${this.distance}]`);
|
|
195
|
-
return `${distance2} ${keyword} ${text}`;
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
var _sameMatchTypes, sameMatchTypes_get, _differentMatchTypes, differentMatchTypes_get;
|
|
199
|
-
var FuzzySearchReport = class {
|
|
200
|
-
constructor(depth = 0) {
|
|
201
|
-
this.depth = depth;
|
|
202
|
-
__privateAdd(this, _sameMatchTypes);
|
|
203
|
-
__privateAdd(this, _differentMatchTypes);
|
|
204
|
-
this.matches = [];
|
|
205
|
-
this.children = [];
|
|
206
|
-
}
|
|
207
|
-
get length() {
|
|
208
|
-
const childLength = this.children.map((it) => it.length).reduce((a, b) => a + b, 0);
|
|
209
|
-
return this.matches.length + childLength;
|
|
210
|
-
}
|
|
211
|
-
addHeading(headingText) {
|
|
212
|
-
this.headingText = headingText;
|
|
213
|
-
return this;
|
|
214
|
-
}
|
|
215
|
-
addMatch(match) {
|
|
216
|
-
this.matches.push(match);
|
|
217
|
-
return this;
|
|
218
|
-
}
|
|
219
|
-
addChild(child) {
|
|
220
|
-
this.children.push(child);
|
|
221
|
-
return this;
|
|
222
|
-
}
|
|
223
|
-
toString() {
|
|
224
|
-
if (this.length === 0) {
|
|
225
|
-
return "";
|
|
226
|
-
}
|
|
227
|
-
const same = __privateGet(this, _sameMatchTypes, sameMatchTypes_get).filter((it) => it.distance < 10).map((it) => it.toString()).join("\n");
|
|
228
|
-
const sameMessage = same.length > 0 ? import_colors_cli.default.italic(`Steps with matching step type:`) : "";
|
|
229
|
-
const different = __privateGet(this, _differentMatchTypes, differentMatchTypes_get).filter((it) => it.distance < 10).map((it) => it.toString()).join("\n");
|
|
230
|
-
const differentMessage = different.length > 0 ? import_colors_cli.default.italic(`Steps with different step type:`) : "";
|
|
231
|
-
const messageArray = [];
|
|
232
|
-
appendSubMessage(messageArray, sameMessage);
|
|
233
|
-
appendSubMessage(messageArray, same);
|
|
234
|
-
appendSubMessage(messageArray, differentMessage);
|
|
235
|
-
appendSubMessage(messageArray, different);
|
|
236
|
-
const children = [];
|
|
237
|
-
this.children.forEach((child) => {
|
|
238
|
-
appendChild(children, child);
|
|
239
|
-
});
|
|
240
|
-
const formatChildren = children.map((it) => it.toString()).join("\n");
|
|
241
|
-
const message = messageArray.join(`
|
|
242
|
-
`).trim();
|
|
243
|
-
const heading = this.headingText && import_colors_cli.default.black(this.headingText);
|
|
244
|
-
return `${heading ?? ""}
|
|
245
|
-
${message.replace(/\r\n|\n|\r/gm, `
|
|
246
|
-
${TAB}`)}
|
|
247
|
-
${formatChildren.replace(/\r\n|\n|\r/gm, `
|
|
248
|
-
${TAB}`)}`;
|
|
72
|
+
// src/parameter-types.ts
|
|
73
|
+
function toPatternArray(pattern) {
|
|
74
|
+
return Array.isArray(pattern) ? [...pattern] : [pattern];
|
|
75
|
+
}
|
|
76
|
+
function buildDefaultValue(rawValues) {
|
|
77
|
+
if (rawValues.length === 0) {
|
|
78
|
+
return void 0;
|
|
249
79
|
}
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
sameMatchTypes_get = function() {
|
|
253
|
-
return this.matches.filter(
|
|
254
|
-
(it) => it instanceof SameStepTypeMatch
|
|
255
|
-
);
|
|
256
|
-
};
|
|
257
|
-
_differentMatchTypes = new WeakSet();
|
|
258
|
-
differentMatchTypes_get = function() {
|
|
259
|
-
return this.matches.filter(
|
|
260
|
-
(it) => it instanceof DifferentStepTypeMatch
|
|
261
|
-
);
|
|
262
|
-
};
|
|
263
|
-
function appendSubMessage(arr, message, prefix) {
|
|
264
|
-
if (message && message.length > 0) {
|
|
265
|
-
const str = prefix ? `${prefix ?? ""}${message ?? ""}` : message ?? "";
|
|
266
|
-
arr.push(str);
|
|
80
|
+
if (rawValues.length === 1) {
|
|
81
|
+
return rawValues[0];
|
|
267
82
|
}
|
|
83
|
+
return [...rawValues];
|
|
268
84
|
}
|
|
269
|
-
function
|
|
270
|
-
if (
|
|
271
|
-
|
|
85
|
+
function resolveScopedName(name, namespace) {
|
|
86
|
+
if (!name || !namespace) {
|
|
87
|
+
return name;
|
|
272
88
|
}
|
|
89
|
+
return `${namespace}:${name}`;
|
|
273
90
|
}
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
var import_overloaded = require("@autometa/overloaded");
|
|
290
|
-
import_cucumber_expressions.ParameterType.prototype.transform = function transform(value, app) {
|
|
291
|
-
return this.transformFn.apply(this, [...value ?? [], app]);
|
|
292
|
-
};
|
|
293
|
-
import_cucumber_expressions.Argument.prototype.getValue = function getValue(app) {
|
|
294
|
-
if (this.group.children.length > 0) {
|
|
295
|
-
const value = this.group.children.filter((it) => it.value !== void 0).map((child) => child.value);
|
|
296
|
-
if (value.length > 0) {
|
|
297
|
-
return this.parameterType.transform(value, app);
|
|
91
|
+
function buildTransform(definition, scopedName, options) {
|
|
92
|
+
return (values, runtime) => {
|
|
93
|
+
const rawValues = values ?? [];
|
|
94
|
+
const resolved = buildDefaultValue(rawValues);
|
|
95
|
+
if (definition.transform) {
|
|
96
|
+
const context = {
|
|
97
|
+
raw: rawValues,
|
|
98
|
+
world: runtime.world,
|
|
99
|
+
name: scopedName,
|
|
100
|
+
originalName: definition.name,
|
|
101
|
+
parameterType: runtime.parameterType,
|
|
102
|
+
definition,
|
|
103
|
+
...options?.namespace !== void 0 ? { namespace: options.namespace } : {}
|
|
104
|
+
};
|
|
105
|
+
return definition.transform(resolved, context);
|
|
298
106
|
}
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
return this.parameterType.transform(groupValues, app);
|
|
302
|
-
};
|
|
303
|
-
var regexp = (0, import_overloaded.instance)(RegExp).or((0, import_overloaded.array)([(0, import_overloaded.instance)(RegExp)]));
|
|
304
|
-
function defineParameterType(registry, ...params) {
|
|
305
|
-
params.forEach((param) => {
|
|
306
|
-
const { name, regex, regexpPattern, transform: transform2, type, primitive } = param;
|
|
307
|
-
return registerParameterType(
|
|
308
|
-
registry,
|
|
309
|
-
name,
|
|
310
|
-
regexpPattern ?? regex,
|
|
311
|
-
transform2,
|
|
312
|
-
type,
|
|
313
|
-
primitive
|
|
314
|
-
);
|
|
315
|
-
});
|
|
107
|
+
return resolved;
|
|
108
|
+
};
|
|
316
109
|
}
|
|
317
|
-
function
|
|
318
|
-
return (0
|
|
319
|
-
(0, import_overloaded.def)(
|
|
320
|
-
(0, import_overloaded.string)(),
|
|
321
|
-
regexp,
|
|
322
|
-
(0, import_overloaded.func)("type"),
|
|
323
|
-
(0, import_overloaded.func)("transform"),
|
|
324
|
-
(0, import_overloaded.func)("primitive")
|
|
325
|
-
).matches((name2, regexp2, type2, transform3, primitive2) => {
|
|
326
|
-
const primitivePrototype = primitive2;
|
|
327
|
-
const typePrototype = type2;
|
|
328
|
-
const wrapper = (val) => {
|
|
329
|
-
const asPrimitive = primitivePrototype(val);
|
|
330
|
-
const asType = new typePrototype(asPrimitive);
|
|
331
|
-
return transform3(asType);
|
|
332
|
-
};
|
|
333
|
-
const param = new import_cucumber_expressions.ParameterType(name2, regexp2, type2, wrapper);
|
|
334
|
-
registry.defineParameterType(param);
|
|
335
|
-
}),
|
|
336
|
-
import_overloaded.def`allTransforms`(
|
|
337
|
-
(0, import_overloaded.string)(),
|
|
338
|
-
regexp,
|
|
339
|
-
(0, import_overloaded.func)("type"),
|
|
340
|
-
(0, import_overloaded.func)("transform"),
|
|
341
|
-
(0, import_overloaded.nil)("primitive")
|
|
342
|
-
).matches((name2, regexp2, type2, transform3) => {
|
|
343
|
-
const typePrototype = type2;
|
|
344
|
-
const wrapper = (val) => {
|
|
345
|
-
const asType = new typePrototype(val);
|
|
346
|
-
return transform3(asType);
|
|
347
|
-
};
|
|
348
|
-
const param = new import_cucumber_expressions.ParameterType(name2, regexp2, type2, wrapper);
|
|
349
|
-
registry.defineParameterType(param);
|
|
350
|
-
}),
|
|
351
|
-
import_overloaded.def`transformPrimitive`(
|
|
352
|
-
(0, import_overloaded.string)(),
|
|
353
|
-
regexp,
|
|
354
|
-
(0, import_overloaded.nil)("type"),
|
|
355
|
-
(0, import_overloaded.func)("transform"),
|
|
356
|
-
(0, import_overloaded.func)("primitive")
|
|
357
|
-
).matches((name2, regexp2, _, transform3, primitive2) => {
|
|
358
|
-
const primitivePrototype = primitive2;
|
|
359
|
-
const wrapper = (val) => {
|
|
360
|
-
const asPrimitive = fromPrimitive(val, primitivePrototype);
|
|
361
|
-
return transform3(asPrimitive);
|
|
362
|
-
};
|
|
363
|
-
const param = new import_cucumber_expressions.ParameterType(name2, regexp2, primitive2, wrapper);
|
|
364
|
-
registry.defineParameterType(param);
|
|
365
|
-
}),
|
|
366
|
-
import_overloaded.def`encapsulatePrimitive`(
|
|
367
|
-
(0, import_overloaded.string)(),
|
|
368
|
-
regexp,
|
|
369
|
-
(0, import_overloaded.func)("type"),
|
|
370
|
-
(0, import_overloaded.nil)("transform"),
|
|
371
|
-
(0, import_overloaded.func)("primitive")
|
|
372
|
-
).matches((name2, regexp2, type2, _, primitive2) => {
|
|
373
|
-
const primitivePrototype = primitive2;
|
|
374
|
-
const typePrototype = type2;
|
|
375
|
-
const wrapper = (val) => {
|
|
376
|
-
const asPrimitive = fromPrimitive(val, primitivePrototype);
|
|
377
|
-
return new typePrototype(asPrimitive);
|
|
378
|
-
};
|
|
379
|
-
const param = new import_cucumber_expressions.ParameterType(name2, regexp2, type2, wrapper);
|
|
380
|
-
registry.defineParameterType(param);
|
|
381
|
-
}),
|
|
382
|
-
import_overloaded.def`makeType`((0, import_overloaded.string)(), regexp, (0, import_overloaded.func)("type"), (0, import_overloaded.nil)(), (0, import_overloaded.nil)()).matches(
|
|
383
|
-
(name2, pattern, type2) => {
|
|
384
|
-
const prototype = type2;
|
|
385
|
-
const transform3 = (val) => new prototype(val);
|
|
386
|
-
const param = new import_cucumber_expressions.ParameterType(name2, pattern, null, transform3);
|
|
387
|
-
registry.defineParameterType(param);
|
|
388
|
-
}
|
|
389
|
-
),
|
|
390
|
-
import_overloaded.def`makePrimitive`(
|
|
391
|
-
(0, import_overloaded.string)(),
|
|
392
|
-
regexp,
|
|
393
|
-
(0, import_overloaded.nil)(),
|
|
394
|
-
(0, import_overloaded.nil)(),
|
|
395
|
-
(0, import_overloaded.func)("primitive")
|
|
396
|
-
).matches((name2, pattern, _, __, primitive2) => {
|
|
397
|
-
const prototype = primitive2;
|
|
398
|
-
const transform3 = (val) => fromPrimitive(val, prototype);
|
|
399
|
-
const param = new import_cucumber_expressions.ParameterType(name2, pattern, null, transform3);
|
|
400
|
-
registry.defineParameterType(param);
|
|
401
|
-
}),
|
|
402
|
-
import_overloaded.def`transformValue`(
|
|
403
|
-
(0, import_overloaded.string)(),
|
|
404
|
-
regexp,
|
|
405
|
-
(0, import_overloaded.nil)(),
|
|
406
|
-
(0, import_overloaded.func)("transform"),
|
|
407
|
-
(0, import_overloaded.nil)()
|
|
408
|
-
).matches((name2, pattern, _, transform3, __) => {
|
|
409
|
-
const param = new import_cucumber_expressions.ParameterType(name2, pattern, null, transform3);
|
|
410
|
-
registry.defineParameterType(param);
|
|
411
|
-
}),
|
|
412
|
-
import_overloaded.def`default`((0, import_overloaded.string)(), (0, import_overloaded.instance)(RegExp), (0, import_overloaded.nil)(), (0, import_overloaded.nil)(), (0, import_overloaded.nil)()).matches(
|
|
413
|
-
(name2, pattern, _, __, ___) => {
|
|
414
|
-
const transform3 = (val) => val;
|
|
415
|
-
const param = new import_cucumber_expressions.ParameterType(name2, pattern, null, transform3);
|
|
416
|
-
registry.defineParameterType(param);
|
|
417
|
-
}
|
|
418
|
-
)
|
|
419
|
-
).use([name, regexpPattern, type, transform2, primitive]);
|
|
110
|
+
function firstValue(input) {
|
|
111
|
+
return Array.isArray(input) ? input[0] : input;
|
|
420
112
|
}
|
|
421
|
-
function
|
|
422
|
-
|
|
423
|
-
|
|
113
|
+
function firstString(input) {
|
|
114
|
+
const value = firstValue(input);
|
|
115
|
+
if (value === void 0 || value === null) {
|
|
116
|
+
return void 0;
|
|
424
117
|
}
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
118
|
+
return String(value);
|
|
119
|
+
}
|
|
120
|
+
function parseNumberValue(input, parser) {
|
|
121
|
+
const raw = firstString(input);
|
|
122
|
+
if (raw === void 0) {
|
|
123
|
+
return null;
|
|
430
124
|
}
|
|
431
|
-
|
|
125
|
+
const numeric = parser(raw);
|
|
126
|
+
return Number.isNaN(numeric) ? null : numeric;
|
|
432
127
|
}
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
var import_asserters = require("@autometa/asserters");
|
|
438
|
-
var import_luxon = require("luxon");
|
|
439
|
-
var strNum = /['"]-?\d+['"]/;
|
|
440
|
-
var isodateRegexp = /(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))/;
|
|
441
|
-
var shortDateRegex = /(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d\.\d+([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\dT[0-2]\d:[0-5]\d:[0-5]\d([+-][0-2]\d:[0-5]\d|Z))|(\d{4}-[01]\d-[0-3]\d)/;
|
|
442
|
-
var boolTypesActive = ["active", "inactive"];
|
|
443
|
-
var boolTypesEnabled = ["enabled", "disabled"];
|
|
444
|
-
var boolTypes = ["true", "false"];
|
|
445
|
-
var OrdinalParam = {
|
|
446
|
-
name: "ordinal",
|
|
447
|
-
regex: /(\d+)(?:st|nd|rd|th)/,
|
|
448
|
-
transform: (value) => parseInt(value, 10)
|
|
449
|
-
};
|
|
450
|
-
var NumberParam = {
|
|
451
|
-
name: "number",
|
|
452
|
-
regex: /\d+/,
|
|
453
|
-
primitive: Number
|
|
454
|
-
};
|
|
455
|
-
var AnyParam = {
|
|
456
|
-
name: "any",
|
|
457
|
-
regex: /.*/
|
|
458
|
-
};
|
|
459
|
-
var UnknownParam = {
|
|
460
|
-
name: "unknown",
|
|
461
|
-
regex: /.*/
|
|
462
|
-
};
|
|
463
|
-
var TextParam = {
|
|
464
|
-
name: "text",
|
|
465
|
-
regex: /"([^"\\]*(\\.[^"\\]*)*)"|'([^'\\]*(\\.[^'\\]*)*)'/,
|
|
466
|
-
primitive: String,
|
|
467
|
-
transform: (value) => {
|
|
468
|
-
const asStr = value;
|
|
469
|
-
return asStr.replace(/^"(.*)"$/, "$1").replace(/^'(.*)'$/, "$1");
|
|
128
|
+
function parseBigIntValue(input) {
|
|
129
|
+
const raw = firstString(input);
|
|
130
|
+
if (raw === void 0) {
|
|
131
|
+
return null;
|
|
470
132
|
}
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
primitive: Boolean
|
|
476
|
-
};
|
|
477
|
-
var BoolParam = {
|
|
478
|
-
name: "bool",
|
|
479
|
-
regex: /true|false/,
|
|
480
|
-
primitive: Boolean
|
|
481
|
-
};
|
|
482
|
-
var DateParam = {
|
|
483
|
-
name: "date",
|
|
484
|
-
regex: [isodateRegexp, shortDateRegex],
|
|
485
|
-
type: Date
|
|
486
|
-
};
|
|
487
|
-
var PrimitiveParam = {
|
|
488
|
-
name: "primitive",
|
|
489
|
-
regex: [
|
|
490
|
-
/true|false/,
|
|
491
|
-
/enabled|disabled/,
|
|
492
|
-
/active|inactive/,
|
|
493
|
-
/null/,
|
|
494
|
-
/empty/,
|
|
495
|
-
/undefined|missing/,
|
|
496
|
-
/NaN/,
|
|
497
|
-
/Infinity/,
|
|
498
|
-
/-Infinity/,
|
|
499
|
-
isodateRegexp,
|
|
500
|
-
shortDateRegex,
|
|
501
|
-
/-?(\d*\.?\d+|\d{1,3}(,\d{3})*(\.\d+)?)/,
|
|
502
|
-
// Comma delimited number, e.g. "1", "1,000", "1,000.00"
|
|
503
|
-
/-?(\d*,?\d+|\d{1,3}(.\d{3})*(,\d+))/,
|
|
504
|
-
// Period delimited number, e.g. "1", "1.000,00"
|
|
505
|
-
/"([^"]*)"/,
|
|
506
|
-
/'([^']*)'/
|
|
507
|
-
],
|
|
508
|
-
transform: (value) => {
|
|
509
|
-
return (0, import_overloaded2.overloads)(
|
|
510
|
-
(0, import_overloaded2.def)((0, import_overloaded2.string)({ equals: "null" })).matches((_) => null),
|
|
511
|
-
(0, import_overloaded2.def)((0, import_overloaded2.string)({ in: ["undefined", "missing"] })).matches((_) => void 0),
|
|
512
|
-
(0, import_overloaded2.def)((0, import_overloaded2.string)({ in: boolTypes })).matches((val) => val === "true"),
|
|
513
|
-
(0, import_overloaded2.def)((0, import_overloaded2.string)({ equals: "NaN" })).matches((_) => NaN),
|
|
514
|
-
(0, import_overloaded2.def)((0, import_overloaded2.string)({ equals: "Infinity" })).matches((_) => Infinity),
|
|
515
|
-
(0, import_overloaded2.def)((0, import_overloaded2.string)({ equals: "-Infinity" })).matches((_) => -Infinity),
|
|
516
|
-
(0, import_overloaded2.def)((0, import_overloaded2.string)({ pattern: isodateRegexp })).matches(parseIso),
|
|
517
|
-
(0, import_overloaded2.def)((0, import_overloaded2.string)({ pattern: shortDateRegex })).matches(parseDate),
|
|
518
|
-
(0, import_overloaded2.def)((0, import_overloaded2.string)({ pattern: strNum })).matches(trimQuotes),
|
|
519
|
-
(0, import_overloaded2.def)((0, import_overloaded2.string)({ pattern: /^-?(\d{1,3}(,\d{3})*(\.\d+)?)/ })).matches(
|
|
520
|
-
(val) => {
|
|
521
|
-
const asStr = val.replace(/,/g, "");
|
|
522
|
-
return parseFloat(asStr);
|
|
523
|
-
}
|
|
524
|
-
),
|
|
525
|
-
// def(string({ pattern: /-?(\d{1,3}(\.\d{3})*(,\d+)?)/ })).matches(
|
|
526
|
-
// (val) =>{
|
|
527
|
-
// const asStr = val.replace(/\./g, "").replace(/,/g, ".");
|
|
528
|
-
// return Number(asStr);
|
|
529
|
-
// }
|
|
530
|
-
// ),
|
|
531
|
-
(0, import_overloaded2.def)((0, import_overloaded2.string)({ in: boolTypesEnabled })).matches(boolEnabled),
|
|
532
|
-
(0, import_overloaded2.def)((0, import_overloaded2.string)({ in: boolTypesActive })).matches(boolActive),
|
|
533
|
-
(0, import_overloaded2.fallback)((val) => {
|
|
534
|
-
(0, import_asserters.AssertIs)(val, "string");
|
|
535
|
-
const fromPhrase = import_datetime.Dates.fromPhrase(val);
|
|
536
|
-
if (fromPhrase && !isNaN(fromPhrase.getTime())) {
|
|
537
|
-
return fromPhrase;
|
|
538
|
-
}
|
|
539
|
-
return val.replace(/^"(.*)"$/, "$1").replace(/^'(.*)'$/, "$1");
|
|
540
|
-
})
|
|
541
|
-
).use([value]);
|
|
133
|
+
try {
|
|
134
|
+
return BigInt(raw);
|
|
135
|
+
} catch {
|
|
136
|
+
return null;
|
|
542
137
|
}
|
|
543
|
-
};
|
|
544
|
-
function boolActive(val) {
|
|
545
|
-
return val === "active";
|
|
546
|
-
}
|
|
547
|
-
function boolEnabled(val) {
|
|
548
|
-
return val === "enabled";
|
|
549
138
|
}
|
|
550
|
-
function
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
139
|
+
function createParameterTypes(options) {
|
|
140
|
+
applyCucumberExtensions();
|
|
141
|
+
const define = (registry, definition) => {
|
|
142
|
+
const patterns = toPatternArray(definition.pattern);
|
|
143
|
+
const scopedName = resolveScopedName(definition.name, options?.namespace);
|
|
144
|
+
const transform = buildTransform(definition, scopedName, options);
|
|
145
|
+
const parameterType = new ParameterType(
|
|
146
|
+
scopedName,
|
|
147
|
+
patterns,
|
|
148
|
+
null,
|
|
149
|
+
// The original transform is overridden by applyCucumberExtensions.
|
|
150
|
+
(...matches) => matches.length <= 1 ? matches[0] : matches,
|
|
151
|
+
definition.useForSnippets,
|
|
152
|
+
definition.preferForRegexpMatch,
|
|
153
|
+
definition.builtin
|
|
154
|
+
);
|
|
155
|
+
attachTransform(parameterType, transform);
|
|
156
|
+
registry.defineParameterType(parameterType);
|
|
157
|
+
return parameterType;
|
|
158
|
+
};
|
|
159
|
+
define.many = (registry, ...definitions) => {
|
|
160
|
+
const list = definitions.length === 1 && Array.isArray(definitions[0]) ? definitions[0] : definitions;
|
|
161
|
+
list.forEach((definition) => {
|
|
162
|
+
define(registry, definition);
|
|
163
|
+
});
|
|
164
|
+
return registry;
|
|
165
|
+
};
|
|
166
|
+
return define;
|
|
555
167
|
}
|
|
556
|
-
|
|
557
|
-
|
|
168
|
+
var defineParameterType = createParameterTypes();
|
|
169
|
+
var INTEGER_REGEXPS = [/-?\d+/, /\d+/];
|
|
170
|
+
var FLOAT_REGEXP = /(?=.*\d.*)[-+]?\d*(?:\.(?=\d.*))?\d*(?:\d+[E][+-]?\d+)?/;
|
|
171
|
+
var WORD_REGEXP = /[^\s]+/;
|
|
172
|
+
var STRING_REGEXP = /"([^"\\]*(\\.[^"\\]*)*)"|'([^'\\]*(\\.[^'\\]*)*)'/;
|
|
173
|
+
var ANONYMOUS_REGEXP = /.*/;
|
|
174
|
+
function createDefaultParameterTypes(options) {
|
|
175
|
+
const define = createParameterTypes(options);
|
|
176
|
+
return (registry) => {
|
|
177
|
+
const defaults = [
|
|
178
|
+
{
|
|
179
|
+
name: "int",
|
|
180
|
+
pattern: INTEGER_REGEXPS,
|
|
181
|
+
transform: (value) => parseNumberValue(value, (raw) => parseInt(raw, 10)),
|
|
182
|
+
useForSnippets: true,
|
|
183
|
+
preferForRegexpMatch: true,
|
|
184
|
+
builtin: true
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
name: "float",
|
|
188
|
+
pattern: FLOAT_REGEXP,
|
|
189
|
+
transform: (value) => parseNumberValue(value, (raw) => parseFloat(raw)),
|
|
190
|
+
useForSnippets: true,
|
|
191
|
+
preferForRegexpMatch: false,
|
|
192
|
+
builtin: true
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: "number",
|
|
196
|
+
pattern: FLOAT_REGEXP,
|
|
197
|
+
transform: (value) => parseNumberValue(value, (raw) => parseFloat(raw)),
|
|
198
|
+
useForSnippets: true,
|
|
199
|
+
preferForRegexpMatch: false,
|
|
200
|
+
builtin: true
|
|
201
|
+
},
|
|
202
|
+
{
|
|
203
|
+
name: "word",
|
|
204
|
+
pattern: WORD_REGEXP,
|
|
205
|
+
transform: (value) => firstString(value) ?? "",
|
|
206
|
+
useForSnippets: false,
|
|
207
|
+
preferForRegexpMatch: false,
|
|
208
|
+
builtin: true
|
|
209
|
+
},
|
|
210
|
+
{
|
|
211
|
+
name: "string",
|
|
212
|
+
pattern: STRING_REGEXP,
|
|
213
|
+
transform: (_value, context) => {
|
|
214
|
+
const [doubleQuoted, singleQuoted] = context.raw;
|
|
215
|
+
const captured = doubleQuoted ?? singleQuoted ?? "";
|
|
216
|
+
return captured.replace(/\\"/g, '"').replace(/\\'/g, "'");
|
|
217
|
+
},
|
|
218
|
+
useForSnippets: true,
|
|
219
|
+
preferForRegexpMatch: false,
|
|
220
|
+
builtin: true
|
|
221
|
+
},
|
|
222
|
+
{
|
|
223
|
+
name: "",
|
|
224
|
+
pattern: ANONYMOUS_REGEXP,
|
|
225
|
+
transform: (_value, context) => context.raw[0] ?? "",
|
|
226
|
+
useForSnippets: false,
|
|
227
|
+
preferForRegexpMatch: true,
|
|
228
|
+
builtin: true
|
|
229
|
+
},
|
|
230
|
+
{
|
|
231
|
+
name: "double",
|
|
232
|
+
pattern: FLOAT_REGEXP,
|
|
233
|
+
transform: (value) => parseNumberValue(value, (raw) => parseFloat(raw)),
|
|
234
|
+
useForSnippets: false,
|
|
235
|
+
preferForRegexpMatch: false,
|
|
236
|
+
builtin: true
|
|
237
|
+
},
|
|
238
|
+
{
|
|
239
|
+
name: "bigdecimal",
|
|
240
|
+
pattern: FLOAT_REGEXP,
|
|
241
|
+
transform: (value) => {
|
|
242
|
+
const text = firstString(value);
|
|
243
|
+
return text ?? null;
|
|
244
|
+
},
|
|
245
|
+
useForSnippets: false,
|
|
246
|
+
preferForRegexpMatch: false,
|
|
247
|
+
builtin: true
|
|
248
|
+
},
|
|
249
|
+
{
|
|
250
|
+
name: "byte",
|
|
251
|
+
pattern: INTEGER_REGEXPS,
|
|
252
|
+
transform: (value) => parseNumberValue(value, (raw) => parseInt(raw, 10)),
|
|
253
|
+
useForSnippets: false,
|
|
254
|
+
preferForRegexpMatch: false,
|
|
255
|
+
builtin: true
|
|
256
|
+
},
|
|
257
|
+
{
|
|
258
|
+
name: "short",
|
|
259
|
+
pattern: INTEGER_REGEXPS,
|
|
260
|
+
transform: (value) => parseNumberValue(value, (raw) => parseInt(raw, 10)),
|
|
261
|
+
useForSnippets: false,
|
|
262
|
+
preferForRegexpMatch: false,
|
|
263
|
+
builtin: true
|
|
264
|
+
},
|
|
265
|
+
{
|
|
266
|
+
name: "long",
|
|
267
|
+
pattern: INTEGER_REGEXPS,
|
|
268
|
+
transform: (value) => parseNumberValue(value, (raw) => parseInt(raw, 10)),
|
|
269
|
+
useForSnippets: false,
|
|
270
|
+
preferForRegexpMatch: false,
|
|
271
|
+
builtin: true
|
|
272
|
+
},
|
|
273
|
+
{
|
|
274
|
+
name: "biginteger",
|
|
275
|
+
pattern: INTEGER_REGEXPS,
|
|
276
|
+
transform: (value) => parseBigIntValue(value),
|
|
277
|
+
useForSnippets: false,
|
|
278
|
+
preferForRegexpMatch: false,
|
|
279
|
+
builtin: true
|
|
280
|
+
}
|
|
281
|
+
];
|
|
282
|
+
const prepared = defaults.map(
|
|
283
|
+
(definition) => options?.namespace && definition.preferForRegexpMatch ? { ...definition, preferForRegexpMatch: false } : definition
|
|
284
|
+
);
|
|
285
|
+
const toRegister = [];
|
|
286
|
+
prepared.forEach((definition) => {
|
|
287
|
+
const scopedName = resolveScopedName(
|
|
288
|
+
definition.name,
|
|
289
|
+
options?.namespace
|
|
290
|
+
);
|
|
291
|
+
const existing = registry.lookupByTypeName(scopedName);
|
|
292
|
+
if (existing) {
|
|
293
|
+
const transform = buildTransform(definition, scopedName, options);
|
|
294
|
+
attachTransform(existing, transform);
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
toRegister.push(definition);
|
|
298
|
+
});
|
|
299
|
+
if (toRegister.length > 0) {
|
|
300
|
+
define.many(registry, ...toRegister);
|
|
301
|
+
}
|
|
302
|
+
return registry;
|
|
303
|
+
};
|
|
558
304
|
}
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
BooleanParam,
|
|
564
|
-
DateParam,
|
|
565
|
-
DifferentStepTypeMatch,
|
|
566
|
-
FuzzySearchReport,
|
|
567
|
-
NumberParam,
|
|
568
|
-
OrdinalParam,
|
|
569
|
-
PrimitiveParam,
|
|
570
|
-
SameStepTypeMatch,
|
|
571
|
-
TextParam,
|
|
572
|
-
UnknownParam,
|
|
573
|
-
buildFuzzySearchReport,
|
|
574
|
-
checkMatch,
|
|
575
|
-
defineParameterType,
|
|
576
|
-
getDiff,
|
|
577
|
-
getDiffs,
|
|
578
|
-
isExpressionCandidate,
|
|
579
|
-
limitDiffs,
|
|
580
|
-
refineDiff
|
|
581
|
-
});
|
|
305
|
+
var defineDefaultParameterTypes = createDefaultParameterTypes();
|
|
306
|
+
|
|
307
|
+
export { applyCucumberExtensions, attachTransform, createDefaultParameterTypes, createParameterTypes, defineDefaultParameterTypes, defineParameterType, resetCucumberExtensions };
|
|
308
|
+
//# sourceMappingURL=out.js.map
|
|
582
309
|
//# sourceMappingURL=index.js.map
|