@@ -35,7 +35,17 @@ var unixPaths = [
35
35
'.\\file' ,
36
36
'./file' ,
37
37
'C:\\foo' ,
38
- ''
38
+ '/' ,
39
+ '' ,
40
+ '.' ,
41
+ '..' ,
42
+ '/foo' ,
43
+ '/foo.' ,
44
+ '/foo.bar' ,
45
+ '/.' ,
46
+ '/.foo' ,
47
+ '/.foo.bar' ,
48
+ '/foo/bar.baz' ,
39
49
] ;
40
50
41
51
var unixSpecialCaseFormatTests = [
@@ -76,6 +86,67 @@ checkErrors(path.posix);
76
86
checkFormat ( path . win32 , winSpecialCaseFormatTests ) ;
77
87
checkFormat ( path . posix , unixSpecialCaseFormatTests ) ;
78
88
89
+ // Test removal of trailing path separators
90
+ const trailingTests = [
91
+ [ path . win32 . parse ,
92
+ [ [ '.\\' , { root : '' , dir : '' , base : '.' , ext : '' , name : '.' } ] ,
93
+ [ '\\\\' , { root : '\\' , dir : '\\' , base : '' , ext : '' , name : '' } ] ,
94
+ [ '\\\\' , { root : '\\' , dir : '\\' , base : '' , ext : '' , name : '' } ] ,
95
+ [ 'c:\\foo\\\\\\' ,
96
+ { root : 'c:\\' , dir : 'c:\\' , base : 'foo' , ext : '' , name : 'foo' } ] ,
97
+ [ 'D:\\foo\\\\\\bar.baz' ,
98
+ { root : 'D:\\' ,
99
+ dir : 'D:\\foo\\\\' ,
100
+ base : 'bar.baz' ,
101
+ ext : '.baz' ,
102
+ name : 'bar'
103
+ }
104
+ ]
105
+ ]
106
+ ] ,
107
+ [ path . posix . parse ,
108
+ [ [ './' , { root : '' , dir : '' , base : '.' , ext : '' , name : '.' } ] ,
109
+ [ '//' , { root : '/' , dir : '/' , base : '' , ext : '' , name : '' } ] ,
110
+ [ '///' , { root : '/' , dir : '/' , base : '' , ext : '' , name : '' } ] ,
111
+ [ '/foo///' , { root : '/' , dir : '/' , base : 'foo' , ext : '' , name : 'foo' } ] ,
112
+ [ '/foo///bar.baz' ,
113
+ { root : '/' , dir : '/foo//' , base : 'bar.baz' , ext : '.baz' , name : 'bar' }
114
+ ]
115
+ ]
116
+ ]
117
+ ] ;
118
+ const failures = [ ] ;
119
+ trailingTests . forEach ( function ( test ) {
120
+ const parse = test [ 0 ] ;
121
+ test [ 1 ] . forEach ( function ( test ) {
122
+ const actual = parse ( test [ 0 ] ) ;
123
+ const expected = test [ 1 ] ;
124
+ const fn = 'path.' +
125
+ ( parse === path . win32 . parse ? 'win32' : 'posix' ) +
126
+ '.parse(' ;
127
+ const message = fn +
128
+ JSON . stringify ( test [ 0 ] ) +
129
+ ')' +
130
+ '\n expect=' + JSON . stringify ( expected ) +
131
+ '\n actual=' + JSON . stringify ( actual ) ;
132
+ const actualKeys = Object . keys ( actual ) ;
133
+ const expectedKeys = Object . keys ( expected ) ;
134
+ let failed = ( actualKeys . length !== expectedKeys . length ) ;
135
+ if ( ! failed ) {
136
+ for ( let i = 0 ; i < actualKeys . length ; ++ i ) {
137
+ const key = actualKeys [ i ] ;
138
+ if ( expectedKeys . indexOf ( key ) === - 1 || actual [ key ] !== expected [ key ] ) {
139
+ failed = true ;
140
+ break ;
141
+ }
142
+ }
143
+ }
144
+ if ( failed )
145
+ failures . push ( '\n' + message ) ;
146
+ } ) ;
147
+ } ) ;
148
+ assert . equal ( failures . length , 0 , failures . join ( '' ) ) ;
149
+
79
150
function checkErrors ( path ) {
80
151
errors . forEach ( function ( errorCase ) {
81
152
try {
0 commit comments