-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest.js
70 lines (64 loc) · 1.66 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
'use strict';
require('mocha');
var assert = require('assert');
var regex = require('./');
function test(str) {
return regex().test(str);
}
describe('dotdir-regex', function() {
describe('regular (non-dot) filepaths', function() {
var notdotfile = [
'a/b.c.d/e.js',
'a/b.js',
'a/b/c/d/e.js',
'./foo',
'/../git',
].forEach(function(filepath) {
it('should not match non-dotfiles: ' + filepath, function() {
assert(!test(filepath));
});
});
});
describe('truthy', function() {
var truthy = [
'.git/foo',
'.github/contributor.md',
'.gitignore/foo',
'.g.i.t.i.g.n.o.r.e/foo',
'a/.b/c/a.js',
'a/.b/c/a.js',
'a/.b/c/.gitignore',
'a/.git/c/a.js',
].forEach(function(filepath) {
it('should be true: ' + filepath, function() {
assert(test(filepath));
});
});
});
describe('falsey', function() {
var falsey = [
'.editorconfig',
'.git',
'.gitignore',
'.travis.yml',
'/.git',
'/.gitignore',
'a/.gitignore',
'a/b.c.d/e.js/.git',
'a/b/c/d/.gitignore',
].forEach(function(filepath) {
it('should be false: ' + filepath, function() {
assert(!test(filepath));
});
});
});
describe('match groups', function() {
it('should match dotfiles', function() {
assert.equal(regex().exec('a/.git/b')[0], '/.git/');
assert.equal(regex().exec('a/.git/b')[1], '.git');
assert.equal(regex().exec('a/.git/b/.gitignore')[1], '.git');
assert.equal(regex().exec('.git/')[1], '.git');
assert.equal(regex().exec('/.git/')[1], '.git');
});
});
});