-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathtest.js
71 lines (64 loc) · 1.61 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
/*!
* dotfile-regex <https://github.com/regexps/dotfile-regex>
*
* Copyright (c) 2015-2017, Jon Schlinkert.
* Released under the MIT License.
*/
'use strict';
require('mocha');
var assert = require('assert');
var regex = require('./');
function test(str) {
return regex().test(str);
}
describe('dotfile-regex', function() {
var notdotfile = [
'a/b/c/d/e.js',
'a/b.c.d/e.js',
'a/b.js',
'a/.b/c/a.js',
].forEach(function(filepath) {
it('should not match non-dotfiles: ' + filepath, function() {
assert(!test(filepath));
});
});
var falsey = [
'./foo',
'.git/foo',
'.github/contributor.md',
'.gitignore/foo',
'a/.b/c/a.js',
'a/.git/c/a.js',
'a/b.c.d/e.js',
'a/b.js',
'/../git',
'a/b/c/d/e.js',
].forEach(function(filepath) {
it('should be false: ' + filepath, function() {
assert(!test(filepath));
});
});
var truthy = [
'.editorconfig',
'.git',
'.gitignore',
'.travis.yml',
'/.git',
'/.gitignore',
'a/.b/c/.gitignore',
'a/.gitignore',
'a/b.c.d/e.js/.git',
'a/b/c/d/.gitignore',
].forEach(function(filepath) {
it('should be true: ' + filepath, function() {
assert(test(filepath));
});
});
it('should match dotfiles', function() {
assert.equal(regex().exec('a/b/c/d/.gitignore')[0], '/.gitignore');
assert.equal(regex().exec('a/.b/c/.gitignore')[0], '/.gitignore');
assert.equal(regex().exec('a/.gitignore')[0], '/.gitignore');
assert.equal(regex().exec('.gitignore')[0], '.gitignore');
assert.equal(regex().exec('/.gitignore')[0], '/.gitignore');
});
});