@@ -35,7 +35,12 @@ var winPaths = [
35
35
'\\\\server two\\shared folder\\file path.zip' ,
36
36
'\\\\teela\\admin$\\system32' ,
37
37
'\\\\?\\UNC\\server\\share'
38
+ ] ;
38
39
40
+ var winSpecialCaseFormatTests = [
41
+ [ { dir : 'some\\dir' } , 'some\\dir\\' ] ,
42
+ [ { base : 'index.html' } , 'index.html' ] ,
43
+ [ { } , '' ]
39
44
] ;
40
45
41
46
var unixPaths = [
@@ -50,25 +55,30 @@ var unixPaths = [
50
55
'C:\\foo'
51
56
] ;
52
57
58
+ var unixSpecialCaseFormatTests = [
59
+ [ { dir : 'some/dir' } , 'some/dir/' ] ,
60
+ [ { base : 'index.html' } , 'index.html' ] ,
61
+ [ { } , '' ]
62
+ ] ;
63
+
53
64
var errors = [
54
65
{ method : 'parse' , input : [ null ] , message : / P a r a m e t e r ' p a t h S t r i n g ' m u s t b e a s t r i n g , n o t / } ,
55
66
{ method : 'parse' , input : [ { } ] , message : / P a r a m e t e r ' p a t h S t r i n g ' m u s t b e a s t r i n g , n o t o b j e c t / } ,
56
67
{ method : 'parse' , input : [ true ] , message : / P a r a m e t e r ' p a t h S t r i n g ' m u s t b e a s t r i n g , n o t b o o l e a n / } ,
57
68
{ method : 'parse' , input : [ 1 ] , message : / P a r a m e t e r ' p a t h S t r i n g ' m u s t b e a s t r i n g , n o t n u m b e r / } ,
58
69
{ method : 'parse' , input : [ ] , message : / P a r a m e t e r ' p a t h S t r i n g ' m u s t b e a s t r i n g , n o t u n d e f i n e d / } ,
59
- // {method: 'parse', input: [''], message: /Invalid path/}, // omitted because it's hard to trigger!
60
70
{ method : 'format' , input : [ null ] , message : / P a r a m e t e r ' p a t h O b j e c t ' m u s t b e a n o b j e c t , n o t / } ,
61
71
{ method : 'format' , input : [ '' ] , message : / P a r a m e t e r ' p a t h O b j e c t ' m u s t b e a n o b j e c t , n o t s t r i n g / } ,
62
72
{ method : 'format' , input : [ true ] , message : / P a r a m e t e r ' p a t h O b j e c t ' m u s t b e a n o b j e c t , n o t b o o l e a n / } ,
63
73
{ method : 'format' , input : [ 1 ] , message : / P a r a m e t e r ' p a t h O b j e c t ' m u s t b e a n o b j e c t , n o t n u m b e r / } ,
64
- { method : 'format' , input : [ { root : true } ] , message : / ' p a t h O b j e c t .r o o t ' m u s t b e a s t r i n g o r u n d e f i n e d , n o t b o o l e a n / } ,
65
- { method : 'format' , input : [ { root : 12 } ] , message : / ' p a t h O b j e c t .r o o t ' m u s t b e a s t r i n g o r u n d e f i n e d , n o t n u m b e r / } ,
66
74
] ;
67
75
68
- check ( path . win32 , winPaths ) ;
69
- check ( path . posix , unixPaths ) ;
76
+ checkParseFormat ( path . win32 , winPaths ) ;
77
+ checkParseFormat ( path . posix , unixPaths ) ;
70
78
checkErrors ( path . win32 ) ;
71
79
checkErrors ( path . posix ) ;
80
+ checkFormat ( path . win32 , winSpecialCaseFormatTests ) ;
81
+ checkFormat ( path . posix , unixSpecialCaseFormatTests ) ;
72
82
73
83
function checkErrors ( path ) {
74
84
errors . forEach ( function ( errorCase ) {
@@ -87,8 +97,7 @@ function checkErrors(path) {
87
97
} ) ;
88
98
}
89
99
90
-
91
- function check ( path , paths ) {
100
+ function checkParseFormat ( path , paths ) {
92
101
paths . forEach ( function ( element , index , array ) {
93
102
var output = path . parse ( element ) ;
94
103
assert . strictEqual ( path . format ( output ) , element ) ;
@@ -97,3 +106,9 @@ function check(path, paths) {
97
106
assert . strictEqual ( output . ext , path . extname ( element ) ) ;
98
107
} ) ;
99
108
}
109
+
110
+ function checkFormat ( path , testCases ) {
111
+ testCases . forEach ( function ( testCase ) {
112
+ assert . strictEqual ( path . format ( testCase [ 0 ] ) , testCase [ 1 ] ) ;
113
+ } ) ;
114
+ }
0 commit comments