Skip to content

Commit

Permalink
adding a check for the sticky regExp option supported by Firefox and …
Browse files Browse the repository at this point in the history
…accepted by the ES6. Note that the tests for this case are checking for the support of the sticky parameter. the logic is still tested by the other expect statements in browsers that do not support sticky but will never enter that block as creating a regExp with that flag is not allowed. Coverage is still good. See #234
  • Loading branch information
yopefonic authored and Davis W. Frank & Rajan Agaskar committed Dec 3, 2012
1 parent 63ad879 commit d946731
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 0 deletions.
3 changes: 3 additions & 0 deletions lib/jasmine-core/jasmine.js
Expand Up @@ -887,6 +887,9 @@ jasmine.Env.prototype.compareRegExps_ = function(a, b, mismatchKeys, mismatchVal
if (a.multiline != b.multiline) if (a.multiline != b.multiline)
mismatchValues.push("expected modifier m was" + (b.multiline ? " " : " not ") + "set and does not equal the origin modifier"); mismatchValues.push("expected modifier m was" + (b.multiline ? " " : " not ") + "set and does not equal the origin modifier");


if (a.sticky != b.sticky)
mismatchValues.push("expected modifier y was" + (b.sticky ? " " : " not ") + "set and does not equal the origin modifier");

return (mismatchValues.length === 0); return (mismatchValues.length === 0);
}; };


Expand Down
7 changes: 7 additions & 0 deletions spec/core/MatchersSpec.js
Expand Up @@ -80,6 +80,13 @@ describe("jasmine.Matchers", function() {
expect((match(/1/i).toNotEqual(/1/i))).toFail(); expect((match(/1/i).toNotEqual(/1/i))).toFail();
expect((match(/[abc]/gm).toEqual(/1/i))).toFail(); expect((match(/[abc]/gm).toEqual(/1/i))).toFail();
expect((match(/[abc]/gm).toNotEqual(/1/i))).toPass(); expect((match(/[abc]/gm).toNotEqual(/1/i))).toPass();

// only test if the browser supports the sticky option on a regExp see pull #234
if (RegExp.prototype.sticky !== undefined) {
var sticky_regexp = new RegExp("[abc]", "y");
expect((match(sticky_regexp).toEqual(/1/i))).toFail();
expect((match(sticky_regexp).toNotEqual(/1/i))).toPass();
}
}); });


it("toEqual to build an Expectation Result", function() { it("toEqual to build an Expectation Result", function() {
Expand Down
3 changes: 3 additions & 0 deletions src/core/Env.js
Expand Up @@ -181,6 +181,9 @@ jasmine.Env.prototype.compareRegExps_ = function(a, b, mismatchKeys, mismatchVal
if (a.multiline != b.multiline) if (a.multiline != b.multiline)
mismatchValues.push("expected modifier m was" + (b.multiline ? " " : " not ") + "set and does not equal the origin modifier"); mismatchValues.push("expected modifier m was" + (b.multiline ? " " : " not ") + "set and does not equal the origin modifier");


if (a.sticky != b.sticky)
mismatchValues.push("expected modifier y was" + (b.sticky ? " " : " not ") + "set and does not equal the origin modifier");

return (mismatchValues.length === 0); return (mismatchValues.length === 0);
}; };


Expand Down

0 comments on commit d946731

Please sign in to comment.