Skip to content

Commit 45cb796

Browse files
test: supports null regex
1 parent 317d88f commit 45cb796

File tree

2 files changed

+11
-16
lines changed

2 files changed

+11
-16
lines changed

assembly/__spec_tests__/generated.spec.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,10 @@ it('line: 1408 - matches "([^\\\\"]+|\\\\.)*" against \'"the \\"quick\\" brown f
20082008
xit("line: 1409 - lazy quantifiers are not supported", () => {});
20092009
xit("line: 1410 - word boundary class not supported yet!", () => {});
20102010
xit("line: 1411 - word boundary class not supported yet!", () => {});
2011-
xit("line: 1412 - test cases for NULL regexes not supported yet", () => {});
2011+
it("line: 1412 - matches against 'abc'", () => {
2012+
const match = exec("", "abc", "s");
2013+
expect(match.matches[0]).toBe("abc".substring(0, 0));
2014+
});
20122015
xit("line: 1413 - requires triage", () => {});
20132016
it("line: 1414 - matches a[^a]b against 'acb'", () => {
20142017
const match = exec("a[^a]b", "acb", "s");

spec/test-generator.js

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,10 @@ lines.forEach((line, index) => {
8181
return;
8282
}
8383

84-
regex = parts[1] == "SAME" ? regex : escapeQuote(parts[1]);
84+
regex =
85+
parts[1] == "SAME"
86+
? regex
87+
: escapeQuote(parts[1] == "NULL" ? "" : parts[1]);
8588
let str = parts[2] !== "NULL" ? escapeQuote(parts[2]) : "";
8689
let flags = parts[0].includes("i") ? "is" : "s";
8790

@@ -90,11 +93,6 @@ lines.forEach((line, index) => {
9093
return;
9194
}
9295

93-
if (regex == "NULL") {
94-
testCase += `xit("line: ${index} - test cases for NULL regexes not supported yet", () => { });`;
95-
return;
96-
}
97-
9896
if (regex.includes("\\b")) {
9997
testCase += `xit("line: ${index} - word boundary class not supported yet!", () => { });`;
10098
return;
@@ -125,26 +123,20 @@ lines.forEach((line, index) => {
125123
return;
126124
}
127125

128-
nextCase += `it("line: ${index} - matches ${regex} against '${
129-
str
130-
}'", () => {
126+
nextCase += `it("line: ${index} - matches ${regex} against '${str}'", () => {
131127
`;
132128
if (parts[3] == "BADBR") {
133129
nextCase += ` expect(() => { let foo = new RegExp("${regex}") }).toThrow();`;
134130
} else if (parts[3] == "NOMATCH") {
135131
nextCase += ` expectNotMatch("${regex}", ["${str}"]);`;
136132
} else {
137-
nextCase += ` const match = exec("${regex}", "${
138-
str
139-
}", "${flags}");`;
133+
nextCase += ` const match = exec("${regex}", "${str}", "${flags}");`;
140134

141135
// create an expect for each capture group
142136
const captures = parts[3].match(/\((\d{1,2}|\?),(\d{1,2}|\?)\)+/g);
143137
captures.forEach((capture, index) => {
144138
const digits = capture.match(/\((\d{1,2}|\?),(\d{1,2}|\?)\)/);
145-
nextCase += `expect(match.matches[${index}]).toBe("${
146-
str
147-
}".substring(${digits[1]}, ${digits[2]}));`;
139+
nextCase += `expect(match.matches[${index}]).toBe("${str}".substring(${digits[1]}, ${digits[2]}));`;
148140
});
149141
}
150142

0 commit comments

Comments
 (0)