-
Notifications
You must be signed in to change notification settings - Fork 126
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
90 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
"use strict"; | ||
|
||
testSetScenario(function() { | ||
describe("flags()", function() { | ||
it("works in modern browsers", function() { | ||
assert.throws(function() { | ||
Parsimmon.regexp(new RegExp("a", "g")); | ||
}); | ||
assert.doesNotThrow(function() { | ||
Parsimmon.regexp(new RegExp("a", "i")); | ||
}); | ||
assert.doesNotThrow(function() { | ||
Parsimmon.regexp(new RegExp("a", "m")); | ||
}); | ||
assert.doesNotThrow(function() { | ||
Parsimmon.regexp(new RegExp("a", "u")); | ||
}); | ||
assert.throws(function() { | ||
Parsimmon.regexp(new RegExp("a", "y")); | ||
}); | ||
}); | ||
|
||
it("works on legacy browsers without Regexp.flags property with flags", function() { | ||
var oldRegExpG = new RegExp("a", "g"); | ||
var oldRegExpI = new RegExp("a", "i"); | ||
var oldRegExpM = new RegExp("a", "m"); | ||
var oldRegExpU = new RegExp("a", "u"); | ||
var oldRegExpY = new RegExp("a", "y"); | ||
var oldRegExps = [ | ||
oldRegExpG, | ||
oldRegExpI, | ||
oldRegExpM, | ||
oldRegExpU, | ||
oldRegExpY | ||
]; | ||
|
||
// Simulate old RegExp without the flags property | ||
oldRegExps.map(function(r) { | ||
Object.defineProperty(r, "flags", { value: undefined }); | ||
assert.strictEqual(r.flags, undefined); | ||
}); | ||
|
||
assert.throws(function() { | ||
Parsimmon.regexp(oldRegExpG); | ||
}); | ||
assert.doesNotThrow(function() { | ||
Parsimmon.regexp(oldRegExpI); | ||
}); | ||
assert.doesNotThrow(function() { | ||
Parsimmon.regexp(oldRegExpM); | ||
}); | ||
assert.doesNotThrow(function() { | ||
Parsimmon.regexp(oldRegExpU); | ||
}); | ||
assert.throws(function() { | ||
Parsimmon.regexp(oldRegExpY); | ||
}); | ||
}); | ||
|
||
it("works on legacy browsers without Regexp.flags property without flags", function() { | ||
var oldRegExp = new RegExp("a", ""); | ||
|
||
// Simulate old RegExp without the flags property | ||
Object.defineProperty(oldRegExp, "flags", { value: undefined }); | ||
assert.strictEqual(oldRegExp.flags, undefined); | ||
|
||
assert.doesNotThrow(function() { | ||
Parsimmon.regexp(oldRegExp); | ||
}); | ||
}); | ||
}); | ||
}); |