-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathends_with.js
More file actions
114 lines (103 loc) · 5.61 KB
/
ends_with.js
File metadata and controls
114 lines (103 loc) · 5.61 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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { PRINTABLE_ASCII } from '../const';
import v from '../voca';
describe('endsWith', function() {
it('should return true for valid ending string', function() {
expect(v.endsWith('Hello World!', '')).toBe(true);
expect(v.endsWith('Hello World!', '!')).toBe(true);
expect(v.endsWith('Hello World!', 'd!')).toBe(true);
expect(v.endsWith('Hello World!', 'rld!')).toBe(true);
expect(v.endsWith('Hello World!', 'orld!')).toBe(true);
expect(v.endsWith('Hello World!', 'World!')).toBe(true);
expect(v.endsWith('Hello World!', ' World!')).toBe(true);
expect(v.endsWith('Hello World!', 'o World!')).toBe(true);
expect(v.endsWith('Hello World!', 'lo World!')).toBe(true);
expect(v.endsWith('Hello World!', 'llo World!')).toBe(true);
expect(v.endsWith('Hello World!', 'ello World!')).toBe(true);
expect(v.endsWith('Hello World!', 'Hello World!')).toBe(true);
expect(v.endsWith('Привет Мир!', 'Мир!')).toBe(true);
expect(v.endsWith('', '')).toBe(true);
expect(v.endsWith(PRINTABLE_ASCII, '~')).toBe(true);
});
it('should return true for valid ending string and position', function() {
expect(v.endsWith('Hello World!', '', 'Hello World'.length)).toBe(true);
expect(v.endsWith('Hello World!', 'Hello World!', 'Hello World!'.length)).toBe(true);
expect(v.endsWith('Hello World!', 'Hello World', 'Hello World!'.length - 1)).toBe(true);
expect(v.endsWith('Hello World!', 'Hello Worl', 'Hello World!'.length - 2)).toBe(true);
expect(v.endsWith('Hello World!', 'Hello Wor', 'Hello World!'.length - 3)).toBe(true);
expect(v.endsWith('Hello World!', 'Hello Wo', 'Hello World!'.length - 4)).toBe(true);
expect(v.endsWith('Hello World!', 'Hello W', 'Hello World!'.length - 5)).toBe(true);
expect(v.endsWith('Hello World!', 'Hello ', 'Hello World!'.length - 6)).toBe(true);
expect(v.endsWith('Hello World!', 'Hello', 'Hello World!'.length - 7)).toBe(true);
expect(v.endsWith('Hello World!', 'Hell', 'Hello World!'.length - 8)).toBe(true);
expect(v.endsWith('Hello World!', 'Hel', 'Hello World!'.length - 9)).toBe(true);
expect(v.endsWith('Hello World!', 'He', 'Hello World!'.length - 10)).toBe(true);
expect(v.endsWith('Hello World!', 'H', 'Hello World!'.length - 11)).toBe(true);
expect(v.endsWith('', '', 0)).toBe(true);
});
it('should return true for a correct downcast of the position', function() {
expect(v.endsWith('Hello World!', 'ello', '5')).toBe(true);
expect(v.endsWith('Hello World!', 'ello', 5.1)).toBe(true);
expect(v.endsWith('Hello World!', 'World!', 30000)).toBe(true);
expect(v.endsWith('Hello World!', 'World!', Infinity)).toBe(true);
});
it('should return true for an empty ending string', function() {
[0, 1, 100, Infinity, undefined, NaN, null].forEach(function(position) {
expect(v.endsWith('Hello World!', '', position)).toBe(true);
});
});
it('should return true for valid ending number', function() {
expect(v.endsWith(1000, 0)).toBe(true);
expect(v.endsWith(1250, 50)).toBe(true);
expect(v.endsWith('916', 16)).toBe(true);
});
it('should return true for a valid ending in a string representation of an object', function() {
expect(v.endsWith(['Welcome to Earth'], 'Earth')).toBe(true);
expect(
v.endsWith(
{
toString: function() {
return 'Let us not stand on ceremony, Mr. Wayne.';
},
},
['Mr. Wayne'],
'Let us not stand on ceremony, Mr. Wayne.'.length - 1
)
).toBe(true);
});
it('should return false for an invalid ending string', function() {
expect(v.endsWith('The shadows betray you, because they belong to me!', 'The shadows')).toBe(false);
expect(v.endsWith('The shadows betray you, because they belong to me!', 'to me')).toBe(false);
expect(v.endsWith('They belong to me!', 'They belong to me')).toBe(false);
expect(v.endsWith('They belong to me!', 'belong')).toBe(false);
expect(v.endsWith('', 'The shadows')).toBe(false);
});
it('should return false for an invalid ending string and position', function() {
expect(v.endsWith('The shadows betray you, because they belong to me!', 'they belong to me!', 5)).toBe(false);
expect(v.endsWith('They belong to me!', 'They belong to me!', 'They belong to me!'.length - 1)).toBe(false);
expect(v.endsWith('They belong to me!', 'They', 'They belong to me!'.length)).toBe(false);
expect(v.endsWith('They belong to me!', 'belong', 'They belong to me!'.length)).toBe(false);
expect(v.endsWith('They belong to me!', 'to me!', 0)).toBe(false);
expect(v.endsWith('They belong to me!', 'belong to me!', -100)).toBe(false);
});
it('should return false for an invalid ending number', function() {
expect(v.endsWith(1000, 10)).toBe(false);
expect(v.endsWith(1250, 55)).toBe(false);
expect(v.endsWith('916', 18)).toBe(false);
});
it('should return false for a NaN position', function() {
expect(v.endsWith('Hello World!', 'World!', NaN)).toBe(false);
});
it('should return false for undefined and null parameters', function() {
expect(v.endsWith()).toBe(false);
expect(v.endsWith(undefined)).toBe(false);
expect(v.endsWith(undefined, undefined)).toBe(false);
expect(v.endsWith(undefined, undefined, undefined)).toBe(false);
expect(v.endsWith(undefined, undefined, 0)).toBe(false);
expect(v.endsWith(undefined, 'Hello World!')).toBe(false);
expect(v.endsWith(null)).toBe(false);
expect(v.endsWith(null, null)).toBe(false);
expect(v.endsWith(null, null, null)).toBe(false);
expect(v.endsWith(null, null, 0)).toBe(false);
expect(v.endsWith(null, 'Hello World!')).toBe(false);
});
});