Skip to content

Commit 5a228af

Browse files
committed
update tests
1 parent 4a26991 commit 5a228af

File tree

1 file changed

+19
-35
lines changed

1 file changed

+19
-35
lines changed

test.js

+19-35
Original file line numberDiff line numberDiff line change
@@ -11,48 +11,32 @@ var assert = require('assert');
1111
var re = require('./');
1212

1313
function match(str) {
14-
return str.match(re());
14+
var res = str.match(re())
15+
return res && res[0];
1516
}
1617

1718
it('should match the last part of a file path:', function () {
18-
assert.equal(match('')[0], '');
19-
assert.equal(match('a')[0], 'a');
20-
assert.equal(match('a/b')[0], 'b');
21-
assert.equal(match('a/b/c/d')[0], 'd');
22-
assert.equal(match('a/b/c/d')[1], 'd');
23-
assert.equal(match('a/b/c/d')[2], '');
24-
assert.equal(match('a/b/c/d')[3], null);
25-
assert.equal(match('a/b/c/d')[4], null);
19+
assert.equal(match(''), null);
20+
assert.equal(match('a'), 'a');
21+
assert.equal(match('a/b'), 'b');
22+
assert.equal(match('a/b/c/d'), 'd');
23+
assert.equal(match('a\\b\\c\\d'), 'd');
2624
});
2725

28-
it('should match the parts in a filename:', function () {
29-
assert.equal(match('abc/xyz.md')[0], 'xyz.md');
30-
assert.equal(match('abc/xyz.md')[1], 'xyz');
31-
assert.equal(match('abc/xyz.md')[2], '.md');
32-
assert.equal(match('abc/xyz.md')[3], '.md');
33-
assert.equal(match('abc/xyz.md')[4], 'md');
26+
it('should match a filename with an extension:', function () {
27+
assert.equal(match('abc/xyz.md'), 'xyz.md');
28+
assert.equal(match('abc\\xyz.md'), 'xyz.md');
29+
assert.equal(match('b.md'), 'b.md');
3430
});
3531

36-
it('should match a file extension:', function () {
37-
assert.equal(match('.md')[0], '.md');
38-
assert.equal(match('.md')[1], '');
39-
assert.equal(match('.md')[2], '.md');
40-
assert.equal(match('.md')[3], '.md');
41-
assert.equal(match('.md')[4], 'md');
32+
it('should match a file name that is only a dotfile or file extension:', function () {
33+
assert.equal(match('.md'), '.md');
34+
assert.equal(match('.dotfile'), '.dotfile');
35+
assert.equal(match('abc\\.gitignore'), '.gitignore');
36+
assert.equal(match('abc/.gitignore'), '.gitignore');
4237
});
4338

44-
it('should match a dotfile:', function () {
45-
assert.equal(match('abc/.gitignore')[0], '.gitignore');
46-
assert.equal(match('abc/.gitignore')[1], '');
47-
assert.equal(match('abc/.gitignore')[2], '.gitignore');
48-
assert.equal(match('abc/.gitignore')[3], '.gitignore');
49-
assert.equal(match('abc/.gitignore')[4], 'gitignore');
50-
});
51-
52-
it('should match a path with dots in the dirname:', function () {
53-
assert.equal(match('a/.b/abc.foo.min.js')[0], 'abc.foo.min.js');
54-
assert.equal(match('a/.b/abc.foo.min.js')[1], 'abc');
55-
assert.equal(match('a/.b/abc.foo.min.js')[2], '.foo.min.js');
56-
assert.equal(match('a/.b/abc.foo.min.js')[3], '.js');
57-
assert.equal(match('a/.b/abc.foo.min.js')[4], 'js');
39+
it('should match the filename when there are dots in the dirname:', function () {
40+
assert.equal(match('a/.b/abc.foo.min.js'), 'abc.foo.min.js');
41+
assert.equal(match('a/b.c.d/foo.js'), 'foo.js');
5842
});

0 commit comments

Comments
 (0)