Skip to content

Commit 12c8e55

Browse files
test: added more complex benchmark example
1 parent bb88704 commit 12c8e55

File tree

3 files changed

+92
-8
lines changed

3 files changed

+92
-8
lines changed

assembly/__spec_tests__/generated.spec.ts

+75-3
Original file line numberDiff line numberDiff line change
@@ -1920,8 +1920,8 @@ it("line: 1309 - matches ^[W-\\]46] against '-46]789'", () => {
19201920
it("line: 1310 - matches ^[W-\\]46] against 'well'", () => {
19211921
expectNotMatch("^[W-\\]46]", ["well"]);
19221922
});
1923-
it("line: 1311 - matches \\d\\d/\\d\\d/\\d\\d\\d\\d against '01/01/2000'", () => {
1924-
const match = exec("\\d\\d/\\d\\d/\\d\\d\\d\\d", "01/01/2000", "s");
1923+
it("line: 1311 - matches \\d\\d\\/\\d\\d\\/\\d\\d\\d\\d against '01/01/2000'", () => {
1924+
const match = exec("\\d\\d\\/\\d\\d\\/\\d\\d\\d\\d", "01/01/2000", "s");
19251925
expect(match.matches[0]).toBe("01/01/2000".substring(0, 10));
19261926
});
19271927
xit("line: 1312 - non capturing groups not supported", () => {});
@@ -2274,7 +2274,79 @@ it("line: 1412 - matches against 'abc'", () => {
22742274
const match = exec("", "abc", "s");
22752275
expect(match.matches[0]).toBe("abc".substring(0, 0));
22762276
});
2277-
xit("line: 1413 - requires triage", () => {});
2277+
it("line: 1413 - matches <tr([\\w\\W\\s\\d][^<>]{0,})><TD([\\w\\W\\s\\d][^<>]{0,})>([\\d]{0,}\\.)(.*)((<BR>([\\w\\W\\s\\d][^<>]{0,})|[\\s]{0,}))<\\/a><\\/TD><TD([\\w\\W\\s\\d][^<>]{0,})>([\\w\\W\\s\\d][^<>]{0,})<\\/TD><TD([\\w\\W\\s\\d][^<>]{0,})>([\\w\\W\\s\\d][^<>]{0,})<\\/TD><\\/TR> against '<TR BGCOLOR='#DBE9E9'><TD align=left valign=top>43.<a href='joblist.cfm?JobID=94 6735&Keyword='>Word Processor<BR>(N-1286)</a></TD><TD align=left valign=top>Lega lstaff.com</TD><TD align=left valign=top>CA - Statewide</TD></TR>'", () => {
2278+
const match = exec(
2279+
"<tr([\\w\\W\\s\\d][^<>]{0,})><TD([\\w\\W\\s\\d][^<>]{0,})>([\\d]{0,}\\.)(.*)((<BR>([\\w\\W\\s\\d][^<>]{0,})|[\\s]{0,}))<\\/a><\\/TD><TD([\\w\\W\\s\\d][^<>]{0,})>([\\w\\W\\s\\d][^<>]{0,})<\\/TD><TD([\\w\\W\\s\\d][^<>]{0,})>([\\w\\W\\s\\d][^<>]{0,})<\\/TD><\\/TR>",
2280+
"<TR BGCOLOR='#DBE9E9'><TD align=left valign=top>43.<a href='joblist.cfm?JobID=94 6735&Keyword='>Word Processor<BR>(N-1286)</a></TD><TD align=left valign=top>Lega lstaff.com</TD><TD align=left valign=top>CA - Statewide</TD></TR>",
2281+
"is"
2282+
);
2283+
expect(match.matches[0]).toBe(
2284+
"<TR BGCOLOR='#DBE9E9'><TD align=left valign=top>43.<a href='joblist.cfm?JobID=94 6735&Keyword='>Word Processor<BR>(N-1286)</a></TD><TD align=left valign=top>Lega lstaff.com</TD><TD align=left valign=top>CA - Statewide</TD></TR>".substring(
2285+
0,
2286+
227
2287+
)
2288+
);
2289+
expect(match.matches[1]).toBe(
2290+
"<TR BGCOLOR='#DBE9E9'><TD align=left valign=top>43.<a href='joblist.cfm?JobID=94 6735&Keyword='>Word Processor<BR>(N-1286)</a></TD><TD align=left valign=top>Lega lstaff.com</TD><TD align=left valign=top>CA - Statewide</TD></TR>".substring(
2291+
3,
2292+
21
2293+
)
2294+
);
2295+
expect(match.matches[2]).toBe(
2296+
"<TR BGCOLOR='#DBE9E9'><TD align=left valign=top>43.<a href='joblist.cfm?JobID=94 6735&Keyword='>Word Processor<BR>(N-1286)</a></TD><TD align=left valign=top>Lega lstaff.com</TD><TD align=left valign=top>CA - Statewide</TD></TR>".substring(
2297+
25,
2298+
47
2299+
)
2300+
);
2301+
expect(match.matches[3]).toBe(
2302+
"<TR BGCOLOR='#DBE9E9'><TD align=left valign=top>43.<a href='joblist.cfm?JobID=94 6735&Keyword='>Word Processor<BR>(N-1286)</a></TD><TD align=left valign=top>Lega lstaff.com</TD><TD align=left valign=top>CA - Statewide</TD></TR>".substring(
2303+
48,
2304+
51
2305+
)
2306+
);
2307+
expect(match.matches[4]).toBe(
2308+
"<TR BGCOLOR='#DBE9E9'><TD align=left valign=top>43.<a href='joblist.cfm?JobID=94 6735&Keyword='>Word Processor<BR>(N-1286)</a></TD><TD align=left valign=top>Lega lstaff.com</TD><TD align=left valign=top>CA - Statewide</TD></TR>".substring(
2309+
51,
2310+
122
2311+
)
2312+
);
2313+
expect(match.matches[5]).toBe(
2314+
"<TR BGCOLOR='#DBE9E9'><TD align=left valign=top>43.<a href='joblist.cfm?JobID=94 6735&Keyword='>Word Processor<BR>(N-1286)</a></TD><TD align=left valign=top>Lega lstaff.com</TD><TD align=left valign=top>CA - Statewide</TD></TR>".substring(
2315+
122,
2316+
122
2317+
)
2318+
);
2319+
expect(match.matches[6]).toBe(
2320+
"<TR BGCOLOR='#DBE9E9'><TD align=left valign=top>43.<a href='joblist.cfm?JobID=94 6735&Keyword='>Word Processor<BR>(N-1286)</a></TD><TD align=left valign=top>Lega lstaff.com</TD><TD align=left valign=top>CA - Statewide</TD></TR>".substring(
2321+
122,
2322+
122
2323+
)
2324+
);
2325+
expect(match.matches[8]).toBe(
2326+
"<TR BGCOLOR='#DBE9E9'><TD align=left valign=top>43.<a href='joblist.cfm?JobID=94 6735&Keyword='>Word Processor<BR>(N-1286)</a></TD><TD align=left valign=top>Lega lstaff.com</TD><TD align=left valign=top>CA - Statewide</TD></TR>".substring(
2327+
134,
2328+
156
2329+
)
2330+
);
2331+
expect(match.matches[9]).toBe(
2332+
"<TR BGCOLOR='#DBE9E9'><TD align=left valign=top>43.<a href='joblist.cfm?JobID=94 6735&Keyword='>Word Processor<BR>(N-1286)</a></TD><TD align=left valign=top>Lega lstaff.com</TD><TD align=left valign=top>CA - Statewide</TD></TR>".substring(
2333+
157,
2334+
172
2335+
)
2336+
);
2337+
expect(match.matches[10]).toBe(
2338+
"<TR BGCOLOR='#DBE9E9'><TD align=left valign=top>43.<a href='joblist.cfm?JobID=94 6735&Keyword='>Word Processor<BR>(N-1286)</a></TD><TD align=left valign=top>Lega lstaff.com</TD><TD align=left valign=top>CA - Statewide</TD></TR>".substring(
2339+
180,
2340+
202
2341+
)
2342+
);
2343+
expect(match.matches[11]).toBe(
2344+
"<TR BGCOLOR='#DBE9E9'><TD align=left valign=top>43.<a href='joblist.cfm?JobID=94 6735&Keyword='>Word Processor<BR>(N-1286)</a></TD><TD align=left valign=top>Lega lstaff.com</TD><TD align=left valign=top>CA - Statewide</TD></TR>".substring(
2345+
203,
2346+
217
2347+
)
2348+
);
2349+
});
22782350
it("line: 1414 - matches a[^a]b against 'acb'", () => {
22792351
const match = exec("a[^a]b", "acb", "s");
22802352
expect(match.matches[0]).toBe("acb".substring(0, 3));

benchmark/benchmark.js

+7
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,13 @@ suite
5454
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.";
5555
executeRegex("[a-l]{3}", text, true);
5656
})
57+
.add("complex regex", () => {
58+
const text =
59+
"<TR BGCOLOR='#DBE9E9'><TD align=left valign=top>43.<a href='joblist.cfm?JobID=94 6735&Keyword='>Word Processor<BR>(N-1286)</a></TD><TD align=left valign=top>Lega lstaff.com</TD><TD align=left valign=top>CA - Statewide</TD></TR>";
60+
const regex =
61+
"<tr([\\w\\W\\s\\d][^<>]{0,})><TD([\\w\\W\\s\\d][^<>]{0,})>([\\d]{0,}\\.)(.*)((<BR>([\\w\\W\\s\\d][^<>]{0,})|[\\s]{0,}))<\\/a><\\/TD><TD([\\w\\W\\s\\d][^<>]{0,})>([\\w\\W\\s\\d][^<>]{0,})<\\/TD><TD([\\w\\W\\s\\d][^<>]{0,})>([\\w\\W\\s\\d][^<>]{0,})<\\/TD><\\/TR>";
62+
executeRegex(regex, text, true);
63+
})
5764
// add listeners
5865
.on("cycle", (event) => {
5966
console.log(String(event.target));

spec/test-generator.js

+10-5
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ const knownIssues = {
3030
// see: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/length
3131
// this is tricky to reproduce
3232
"test requires a substring function": [1087, 1088],
33-
"requires triage": [1413, ...range(1301, 1308)],
33+
"requires triage": [...range(1301, 1308)],
3434
"test indicates a malformed regex, whereas it appears OK in JS": [1189],
3535
"JS does not support the \\A \\Z syntax for start and end of string": [
3636
1163,
@@ -81,7 +81,10 @@ lines.forEach((line, index) => {
8181
regex =
8282
parts[1] == "SAME"
8383
? regex
84-
: escapeQuote(parts[1] == "NULL" ? "" : parts[1]);
84+
: escapeQuote(parts[1] == "NULL" ? "" : parts[1]).replaceAll(
85+
"/",
86+
"\\\\/"
87+
);
8588
let str = parts[2] !== "NULL" ? escapeQuote(parts[2]) : "";
8689
let flags = parts[0].includes("i") ? "is" : "s";
8790

@@ -130,10 +133,12 @@ lines.forEach((line, index) => {
130133
nextCase += ` const match = exec("${regex}", "${str}", "${flags}");`;
131134

132135
// create an expect for each capture group
133-
const captures = parts[3].match(/\((\d{1,2}|\?),(\d{1,2}|\?)\)+/g);
136+
const captures = parts[3].match(/\((\d{1,3}|\?),(\d{1,3}|\?)\)+/g);
134137
captures.forEach((capture, index) => {
135-
const digits = capture.match(/\((\d{1,2}|\?),(\d{1,2}|\?)\)/);
136-
nextCase += `expect(match.matches[${index}]).toBe("${str}".substring(${digits[1]}, ${digits[2]}));`;
138+
const digits = capture.match(/\((\d{1,3}|\?),(\d{1,3}|\?)\)/);
139+
if (digits[1] !== "?") {
140+
nextCase += `expect(match.matches[${index}]).toBe("${str}".substring(${digits[1]}, ${digits[2]}));`;
141+
}
137142
});
138143
}
139144

0 commit comments

Comments
 (0)