-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathmatches.js
More file actions
68 lines (60 loc) · 2.71 KB
/
matches.js
File metadata and controls
68 lines (60 loc) · 2.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import { PRINTABLE_ASCII } from '../const';
import v from '../voca';
describe('matches', function() {
it('should return true for a string that matches a regular expression object', function() {
expect(v.matches('pacific ocean', /ocean/)).toBe(true);
expect(v.matches('pacific ocean', /^pacific ocean$/)).toBe(true);
expect(v.matches(undefined, /.?/)).toBe(true);
expect(v.matches(null, /.?/)).toBe(true);
});
it('should return true for a string that matches a regular expression string', function() {
expect(v.matches('pacific ocean', 'ocean')).toBe(true);
expect(v.matches('pacific ocean', '^pacific ocean$')).toBe(true);
expect(v.matches('pacific ocean', 'PACIFIC', 'i')).toBe(true);
expect(v.matches('pacific ocean', '\\s')).toBe(true);
expect(v.matches(undefined, '.?')).toBe(true);
expect(v.matches(null, '.?')).toBe(true);
expect(v.matches(PRINTABLE_ASCII, 's')).toBe(true);
});
it('should return true for a string that matches a string representation of an object', function() {
expect(v.matches(['atlantic ocean'], /atlantic/)).toBe(true);
expect(v.matches('pacific ocean', ['^pacific ocean$'])).toBe(true);
expect(
v.matches(
{
toString: function() {
return 'pacific ocean';
},
},
'PACIFIC',
'i'
)
).toBe(true);
expect(v.matches(['pacific ocean'], ['\\s'])).toBe(true);
});
it('should return true for a number that matches a regular expression', function() {
expect(v.matches(1500, /\d/)).toBe(true);
expect(v.matches(685, 68)).toBe(true);
expect(v.matches(-1.5, /^\-1\.5$/)).toBe(true);
});
it('should return true for a boolean that matches a regular expression', function() {
expect(v.matches(true, /true/)).toBe(true);
expect(v.matches(false, 'false')).toBe(true);
});
it('should return false for a string that does not match a regular expression object', function() {
expect(v.matches('pacific ocean', /^ocean/)).toBe(false);
expect(v.matches('pacific ocean', /^atlantic ocean$/)).toBe(false);
expect(v.matches(undefined, /a/)).toBe(false);
});
it('should return false for a string that does not match a regular expression string', function() {
expect(v.matches('pacific ocean', 'sea')).toBe(false);
expect(v.matches('pacific ocean', '^atlantic ocean$')).toBe(false);
expect(v.matches('pacific ocean', 'PACIFIC')).toBe(false);
expect(v.matches('pacific ocean', '\\n')).toBe(false);
expect(v.matches(undefined, 's')).toBe(false);
});
it('should return false for a null or undefined pattern', function() {
expect(v.matches('pacific ocean', undefined)).toBe(false);
expect(v.matches('pacific ocean', null)).toBe(false);
});
});