Skip to content

Commit

Permalink
[[CHORE]] Improve test coverage for RegExp parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
jugglinmike authored and rwaldron committed Jun 24, 2019
1 parent 5ac5c46 commit 2366c92
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
7 changes: 0 additions & 7 deletions src/lex.js
Expand Up @@ -1352,17 +1352,11 @@ Lexer.prototype = {
sequence = char;
next = this.peek(index + 1);
while (reg.nonzeroDigit.test(next) || next === "0") {
/* istanbul ignore next */
index += 1;
/* istanbul ignore next */
char = next;
/* istanbul ignore next */
sequence += char;
/* istanbul ignore next */
body += char;
/* istanbul ignore next */
value += char;
/* istanbul ignore next */
next = this.peek(index + 1);
}
groupReferences.push(Number(sequence));
Expand Down Expand Up @@ -1471,7 +1465,6 @@ Lexer.prototype = {
}

if (next === "}") {
/* istanbul ignore next */
return true;
}

Expand Down
29 changes: 29 additions & 0 deletions tests/unit/parser.js
Expand Up @@ -756,6 +756,16 @@ exports.regexp.uFlag = function (test) {
.addError(1, 6, "Invalid regular expression.")
.test("void /.{}/u;", { esversion: 6 });

TestRun(test)
.test([
"void /.{0}/;",
"void /.{0}/u;",
"void /.{9}/;",
"void /.{9}/u;",
"void /.{23}/;",
"void /.{23}/u;"
], { esversion: 6 });

TestRun(test)
.addError(1, 6, "Invalid regular expression.")
.test("void /.{,2}/u;", { esversion: 6 });
Expand All @@ -768,6 +778,25 @@ exports.regexp.uFlag = function (test) {
.addError(1, 6, "Invalid regular expression.")
.test("void /(.)(.)\\3/u;", { esversion: 6 });

TestRun(test, "Valid group reference - multiple digits")
.test([
"void /(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)\\10/u;",
"void /(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)\\10a/u;",
"void /(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)\\11/u;",
"void /(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)\\11a/u;"
], { esversion: 6 });

// A negative syntax test is the only way to verify JSHint is interpeting the
// adjacent digits as one reference as opposed to a reference followed by a
// literal digit.
TestRun(test, "Invalid group reference - two digits")
.addError(1, 6, "Invalid regular expression.")
.test("void /(.)\\10/u;", { esversion: 6 });

TestRun(test, "Invalid group reference - three digits")
.addError(1, 6, "Invalid regular expression.")
.test("void /(.)(.)(.)(.)(.)(.)(.)(.)(.)(.)\\100/u;", { esversion: 6 });

TestRun(test, "Invalid group reference (permitted without flag)")
.test("void /(.)(.)\\3/;", { esversion: 6 });

Expand Down

0 comments on commit 2366c92

Please sign in to comment.