-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.js
83 lines (72 loc) · 3.12 KB
/
test.js
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
'use strict';
require('mocha');
var assert = require('assert');
var endsWith = require('./');
describe('endsWith', function() {
it('should be false when the substring or filepath are empty strings', function() {
assert(!endsWith('foo\\bar\\baz\\', ''));
assert(!endsWith('', 'foo\\bar\\baz\\'));
assert(!endsWith('', ''));
});
it('should work when the path ends with unix slashes', function() {
assert(endsWith('foo/bar/baz/', 'baz/'));
assert(endsWith('foo/bar/baz//', 'baz//'));
assert(!endsWith('foo/bar/baz', 'baz/'));
});
it('should work when the path ends with windows slashes', function() {
assert(endsWith('foo\\bar\\baz\\', 'baz/'));
assert(endsWith('foo\\bar\\baz\\', 'baz\\'));
assert(endsWith('foo\\bar\\baz\\\\', 'baz\\\\'));
assert(!endsWith('foo\\bar\\baz', 'baz\\\\'));
});
it('should be true when the path ends with a string', function() {
assert(endsWith('foo/bar/baz.js', '/baz.js'));
assert(endsWith('foo/bar/baz.js', '/bar/baz.js'));
assert(endsWith('foo/bar/baz.js', 'baz.js'));
assert(endsWith('foo/bar/baz.js', 'bar/baz.js'));
assert(endsWith('foo/bar/baz', '/baz'));
assert(endsWith('foo/bar/baz', 'bar/baz'));
assert(endsWith('foo\\bar\\baz.md', 'baz.md'));
assert(endsWith('foo\\bar\\baz.md', 'bar/baz.md'));
assert(!endsWith('foo\\bar\\baz.md', 'z.md'));
});
it('should be true when the path ends with a file extension', function() {
assert(endsWith('foo/bar/baz.md', 'md'));
assert(endsWith('foo/bar/baz.md', '.md'));
assert(endsWith('foo\\bar\\baz.md', 'md'));
assert(endsWith('foo\\bar\\baz.md', '.md'));
assert(!endsWith('foo/bar.md/baz', '.md'));
assert(!endsWith('foo/.git/baz', '.git'));
});
it('should be false when the path does not end with the string', function() {
assert(!endsWith('foo\\bar\\baz.md', '/'));
assert(!endsWith('foo\\bar\\baz.md', 'baz'));
});
it('should be false when the substring is a "partial" match', function() {
assert(!endsWith('foo\\bar\\bazqux', 'qux'));
assert(!endsWith('foo\\bar\\baz.md', 'baz'));
assert(!endsWith('foo\\bar\\baz.md', 'r\\baz.md'));
assert(endsWith('foo\\bar\\bazqux', 'qux', { partialMatch: true }));
assert(endsWith('foo\\bar\\baz.md', 'r\\baz.md', { partialMatch: true }));
assert(endsWith('foo\\bar\\baz.md', 'r/baz.md', { partialMatch: true }));
});
it('should be case sensitive by default', function() {
assert(!endsWith('foo/bar', 'BAR'));
assert(!endsWith('foo/bar/baz', 'BAR/baz'));
});
it('should not be case sensitive when options.nocase is true', function() {
assert(endsWith('foo/bar', 'BAR', { nocase: true }));
assert(endsWith('foo/bar/baz', 'BAR/baz', { nocase: true }));
});
it('should correctly handle trailing slashes', function() {
assert(endsWith('/foo/', '/'));
assert(endsWith('/foo/', '/foo/'));
assert(!endsWith('/foo', '/'));
assert(!endsWith('/foo', 'foo/'));
assert(!endsWith('/foo', '/foo/'));
assert(!endsWith('/foo/', '//'));
assert(!endsWith('/foo/', '///'));
assert(!endsWith('/foo/', '\\\\'));
assert(!endsWith('/foo/', '\\'));
});
});