Skip to content

Commit

Permalink
100% test coverage
Browse files Browse the repository at this point in the history
  • Loading branch information
ekilah committed Aug 25, 2020
1 parent 37b45b1 commit 0577c93
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 5 deletions.
3 changes: 3 additions & 0 deletions test/.eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,8 @@
"Parsimmon": true,
"assert": true,
"testSetScenario": true
},
"rules": {
"no-invalid-regexp": ["error", {"allowConstructorFlags": ["u", "y"]}]
}
}
24 changes: 19 additions & 5 deletions test/core/flags.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,33 @@
testSetScenario(function() {
describe("Parsimmon.flags()", function() {
it("works in modern browsers", function() {
var flags = Parsimmon.flags(/a/gim);
assert.strictEqual(flags, "gim");
// eslint-disable-next-line no-invalid-regexp
var flags = Parsimmon.flags(new RegExp("a", "gimuy"));
assert.strictEqual(flags, "gimuy");
});

it("works on legacy browsers without Regexp.flags property", function() {
var oldRegExp = /a/gim;
it("works on legacy browsers without Regexp.flags property with flags", function() {
// eslint-disable-next-line no-invalid-regexp
var oldRegExp = new RegExp("a", "gimuy");

// Simulate old RegExp without the flags property
Object.defineProperty(oldRegExp, "flags", { value: undefined });
assert.strictEqual(oldRegExp.flags, undefined);

var flags = Parsimmon.flags(oldRegExp);
assert.strictEqual(flags, "gim");
assert.strictEqual(flags, "gimuy");
});

it("works on legacy browsers without Regexp.flags property without flags", function() {
// eslint-disable-next-line no-invalid-regexp
var oldRegExp = new RegExp("a", "");

// Simulate old RegExp without the flags property
Object.defineProperty(oldRegExp, "flags", { value: undefined });
assert.strictEqual(oldRegExp.flags, undefined);

var flags = Parsimmon.flags(oldRegExp);
assert.strictEqual(flags, "");
});
});
});

0 comments on commit 0577c93

Please sign in to comment.