@@ -3,6 +3,12 @@ var fs = require('fs')
3
3
var test = require ( 'tap' ) . test ;
4
4
var glob = require ( '../' ) ;
5
5
6
+ var cwd = process . cwd ( )
7
+ var drive = 'c'
8
+ if ( / ^ [ a - z A - Z ] : [ \\ \/ ] / . test ( cwd ) ) {
9
+ drive = cwd . charAt ( 0 ) . toLowerCase ( )
10
+ }
11
+
6
12
test ( 'mock fs' , function ( t ) {
7
13
var stat = fs . stat
8
14
var statSync = fs . statSync
@@ -12,10 +18,10 @@ test('mock fs', function(t) {
12
18
function fakeStat ( path ) {
13
19
var ret
14
20
switch ( path . toLowerCase ( ) . replace ( / \\ / g, '/' ) ) {
15
- case '/tmp' : case '/tmp/' : case 'c :\\tmp' : case 'c :\\tmp\\' :
21
+ case '/tmp' : case '/tmp/' : case drive + ' :\\tmp' : case drive + ' :\\tmp\\' :
16
22
ret = { isDirectory : function ( ) { return true } }
17
23
break
18
- case '/tmp/a' : case 'c :/tmp/a' :
24
+ case '/tmp/a' : case drive + ' :/tmp/a' :
19
25
ret = { isDirectory : function ( ) { return false } }
20
26
break
21
27
}
@@ -40,10 +46,10 @@ test('mock fs', function(t) {
40
46
function fakeReaddir ( path ) {
41
47
var ret
42
48
switch ( path . toLowerCase ( ) . replace ( / \\ / g, '/' ) ) {
43
- case '/tmp' : case '/tmp/' : case 'c :/tmp' : case 'c :/tmp/' :
49
+ case '/tmp' : case '/tmp/' : case drive + ' :/tmp' : case drive + ' :/tmp/' :
44
50
ret = [ 'a' , 'A' ]
45
51
break
46
- case '/' : case 'c :/' :
52
+ case '/' : case drive + ' :/' :
47
53
ret = [ 'tmp' , 'tMp' , 'tMP' , 'TMP' ]
48
54
}
49
55
return ret
@@ -79,15 +85,15 @@ test('nocase, nomagic', function(t) {
79
85
'/tmp/a' ]
80
86
if ( process . platform . match ( / ^ w i n / ) ) {
81
87
want = want . map ( function ( p ) {
82
- return 'c :' + p
88
+ return drive + ' :' + p
83
89
} )
84
90
}
85
91
glob ( '/tmp/a' , { nocase : true } , function ( er , res ) {
86
92
if ( er )
87
93
throw er
88
94
if ( process . platform . match ( / ^ w i n / ) )
89
95
res = res . map ( function ( r ) {
90
- return r . replace ( / \\ / g, '/' ) . replace ( / ^ C : / , 'c :')
96
+ return r . replace ( / \\ / g, '/' ) . replace ( new RegExp ( '^' + drive + ':' ) , drive + ' :')
91
97
} )
92
98
t . same ( res . sort ( ) , want )
93
99
if ( -- n === 0 ) t . end ( )
@@ -97,7 +103,7 @@ test('nocase, nomagic', function(t) {
97
103
throw er
98
104
if ( process . platform . match ( / ^ w i n / ) )
99
105
res = res . map ( function ( r ) {
100
- return r . replace ( / \\ / g, '/' ) . replace ( / ^ C : / , 'c :')
106
+ return r . replace ( / \\ / g, '/' ) . replace ( new RegExp ( '^' + drive + ':' ) , drive + ' :')
101
107
} )
102
108
t . same ( res . sort ( ) , want )
103
109
if ( -- n === 0 ) t . end ( )
@@ -116,7 +122,7 @@ test('nocase, with some magic', function(t) {
116
122
'/tmp/a' ]
117
123
if ( process . platform . match ( / ^ w i n / ) ) {
118
124
want = want . map ( function ( p ) {
119
- return 'c :' + p
125
+ return drive + ' :' + p
120
126
} )
121
127
}
122
128
0 commit comments