@@ -11,48 +11,32 @@ var assert = require('assert');
11
11
var re = require ( './' ) ;
12
12
13
13
function match ( str ) {
14
- return str . match ( re ( ) ) ;
14
+ var res = str . match ( re ( ) )
15
+ return res && res [ 0 ] ;
15
16
}
16
17
17
18
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' ) ;
26
24
} ) ;
27
25
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' ) ;
34
30
} ) ;
35
31
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' ) ;
42
37
} ) ;
43
38
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' ) ;
58
42
} ) ;
0 commit comments