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:
21
spec/core/asymmetric_equality/StringMatchingSpec.js
Normal file
21
spec/core/asymmetric_equality/StringMatchingSpec.js
Normal file
@@ -0,0 +1,21 @@
|
||||
describe("StringMatching", function() {
|
||||
it("matches a string against a provided regexp", function() {
|
||||
var matcher = new j$.StringMatching(/foo/);
|
||||
|
||||
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
||||
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
||||
});
|
||||
|
||||
it("matches a string against provided string", function() {
|
||||
var matcher = new j$.StringMatching('foo');
|
||||
|
||||
expect(matcher.asymmetricMatch('barfoobaz')).toBe(true);
|
||||
expect(matcher.asymmetricMatch('barbaz')).toBe(false);
|
||||
});
|
||||
|
||||
it("raises an Error when the expected is not a String or RegExp", function() {
|
||||
expect(function() {
|
||||
new j$.StringMatching({});
|
||||
}).toThrowError(/not a String or a RegExp/);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user