Add asymmetric equality tester to match a string against a regexp
- Also move the asymmetric testers into their own dir for easier locating. [#58120558] Fix #243
This commit is contained in:
16
src/core/asymmetric_equality/StringMatching.js
Normal file
16
src/core/asymmetric_equality/StringMatching.js
Normal file
@@ -0,0 +1,16 @@
|
||||
getJasmineRequireObj().StringMatching = function(j$) {
|
||||
|
||||
function StringMatching(expected) {
|
||||
if (!j$.isString_(expected) && !j$.isA_('RegExp', expected)) {
|
||||
throw new Error('Expected is not a String or a RegExp');
|
||||
}
|
||||
|
||||
this.regexp = new RegExp(expected);
|
||||
}
|
||||
|
||||
StringMatching.prototype.asymmetricMatch = function(other) {
|
||||
return this.regexp.test(other);
|
||||
};
|
||||
|
||||
return StringMatching;
|
||||
};
|
||||
@@ -53,6 +53,10 @@ getJasmineRequireObj().base = function(j$, jasmineGlobal) {
|
||||
return new j$.ObjectContaining(sample);
|
||||
};
|
||||
|
||||
j$.stringMatching = function(expected) {
|
||||
return new j$.StringMatching(expected);
|
||||
};
|
||||
|
||||
j$.createSpy = function(name, originalFn) {
|
||||
|
||||
var spyStrategy = new j$.SpyStrategy({
|
||||
|
||||
@@ -36,6 +36,7 @@ getJasmineRequireObj = (function (jasmineGlobal) {
|
||||
j$.Spec = jRequire.Spec(j$);
|
||||
j$.SpyRegistry = jRequire.SpyRegistry(j$);
|
||||
j$.SpyStrategy = jRequire.SpyStrategy();
|
||||
j$.StringMatching = jRequire.StringMatching(j$);
|
||||
j$.Suite = jRequire.Suite();
|
||||
j$.Timer = jRequire.Timer();
|
||||
j$.version = jRequire.version();
|
||||
|
||||
Reference in New Issue
Block a user