@@ -55,48 +55,75 @@ mod tests {
55
55
use crate :: configure:: context:: Context ;
56
56
use crate :: parser:: Statement ;
57
57
58
+ const SEPARATOR : char = std:: path:: MAIN_SEPARATOR ;
59
+
58
60
#[ test]
59
61
fn start_with_drive_letter ( ) {
60
62
let mut parser = Statement :: new ( ) . unwrap ( ) ;
61
- let separator = std:: path:: MAIN_SEPARATOR ;
62
63
let result = parser. parse_and_execute ( "[path('C:','test')]" , & Context :: new ( ) ) . unwrap ( ) ;
63
- assert_eq ! ( result, format!( "C:{separator }test" ) ) ;
64
+ assert_eq ! ( result, format!( "C:{SEPARATOR }test" ) ) ;
64
65
}
65
66
66
67
#[ test]
67
68
fn drive_letter_in_middle ( ) {
68
69
let mut parser = Statement :: new ( ) . unwrap ( ) ;
69
- let separator = std:: path:: MAIN_SEPARATOR ;
70
70
let result = parser. parse_and_execute ( "[path('a','C:','test')]" , & Context :: new ( ) ) . unwrap ( ) ;
71
71
72
- // if any part of the path is absolute, it replaces it instead of appending
72
+ // if any part of the path is absolute, it replaces it instead of appending on Windows
73
+ #[ cfg( target_os = "windows" ) ]
74
+ assert_eq ! ( result, format!( "C:{SEPARATOR}test" ) ) ;
75
+
76
+ // non-Windows, the colon is a valid character in a path
77
+ #[ cfg( not( target_os = "windows" ) ) ]
78
+ assert_eq ! ( result, format!( "a{SEPARATOR}C:{SEPARATOR}test" ) ) ;
79
+ }
80
+
81
+ #[ test]
82
+ fn multiple_drive_letters ( ) {
83
+ let mut parser = Statement :: new ( ) . unwrap ( ) ;
84
+ let result = parser. parse_and_execute ( "[path('C:','D:','test')]" , & Context :: new ( ) ) . unwrap ( ) ;
85
+
86
+ // if any part of the path is absolute, it replaces it instead of appending on Windows
73
87
#[ cfg( target_os = "windows" ) ]
74
- assert_eq ! ( result, format!( "C:{separator}test" ) ) ;
88
+ assert_eq ! ( result, format!( "D:{SEPARATOR}test" ) ) ;
89
+
90
+ // non-Windows, the colon is a valid character in a path
75
91
#[ cfg( not( target_os = "windows" ) ) ]
76
- assert_eq ! ( result, format!( "a{separator}C:{separator}test" ) ) ;
92
+ assert_eq ! ( result, format!( "C:{SEPARATOR}D:{SEPARATOR}test" ) ) ;
93
+ }
94
+
95
+ #[ test]
96
+ fn relative_path ( ) {
97
+ let mut parser = Statement :: new ( ) . unwrap ( ) ;
98
+ let result = parser. parse_and_execute ( "[path('a','..','b')]" , & Context :: new ( ) ) . unwrap ( ) ;
99
+ assert_eq ! ( result, format!( "a{SEPARATOR}..{SEPARATOR}b" ) ) ;
100
+ }
101
+
102
+ #[ test]
103
+ fn path_segement_with_separator ( ) {
104
+ let mut parser = Statement :: new ( ) . unwrap ( ) ;
105
+ let result = parser. parse_and_execute ( format ! ( "[path('a','b{SEPARATOR}c')]" ) . as_str ( ) , & Context :: new ( ) ) . unwrap ( ) ;
106
+ assert_eq ! ( result, format!( "a{SEPARATOR}b{SEPARATOR}c" ) ) ;
77
107
}
78
108
79
109
#[ test]
80
110
fn unix_absolute_path ( ) {
81
111
let mut parser = Statement :: new ( ) . unwrap ( ) ;
82
- let separator = std:: path:: MAIN_SEPARATOR ;
83
112
let result = parser. parse_and_execute ( "[path('/','a','b')]" , & Context :: new ( ) ) . unwrap ( ) ;
84
- assert_eq ! ( result, format!( "/a{separator }b" ) ) ;
113
+ assert_eq ! ( result, format!( "/a{SEPARATOR }b" ) ) ;
85
114
}
86
115
87
116
#[ test]
88
117
fn two_args ( ) {
89
118
let mut parser = Statement :: new ( ) . unwrap ( ) ;
90
- let separator = std:: path:: MAIN_SEPARATOR ;
91
119
let result = parser. parse_and_execute ( "[path('a','b')]" , & Context :: new ( ) ) . unwrap ( ) ;
92
- assert_eq ! ( result, format!( "a{separator }b" ) ) ;
120
+ assert_eq ! ( result, format!( "a{SEPARATOR }b" ) ) ;
93
121
}
94
122
95
123
#[ test]
96
124
fn three_args ( ) {
97
125
let mut parser = Statement :: new ( ) . unwrap ( ) ;
98
- let separator = std:: path:: MAIN_SEPARATOR ;
99
126
let result = parser. parse_and_execute ( "[path('a','b','c')]" , & Context :: new ( ) ) . unwrap ( ) ;
100
- assert_eq ! ( result, format!( "a{separator }b{separator }c" ) ) ;
127
+ assert_eq ! ( result, format!( "a{SEPARATOR }b{SEPARATOR }c" ) ) ;
101
128
}
102
129
}
0 commit comments