1
+ use assert_matches:: assert_matches;
1
2
use bstr:: ByteSlice ;
2
3
use gix_url:: Scheme ;
3
4
4
- use crate :: parse:: { assert_url , assert_url_roundtrip, url, url_alternate} ;
5
+ use crate :: parse:: { assert_url_roundtrip, url, url_alternate} ;
5
6
6
7
#[ test]
7
8
fn file_path_with_protocol ( ) -> crate :: Result {
@@ -18,42 +19,37 @@ fn file_to_root() -> crate::Result {
18
19
19
20
#[ test]
20
21
fn file_path_without_protocol ( ) -> crate :: Result {
21
- let url = assert_url (
22
+ assert_url_roundtrip (
22
23
"/path/to/git" ,
23
24
url_alternate ( Scheme :: File , None , None , None , b"/path/to/git" ) ,
24
- ) ?
25
- . to_bstring ( ) ;
26
- assert_eq ! ( url, "/path/to/git" ) ;
27
- Ok ( ( ) )
25
+ )
28
26
}
29
27
30
28
#[ test]
31
29
fn no_username_expansion_for_file_paths_without_protocol ( ) -> crate :: Result {
32
- let url = assert_url (
30
+ assert_url_roundtrip (
33
31
"~/path/to/git" ,
34
32
url_alternate ( Scheme :: File , None , None , None , b"~/path/to/git" ) ,
35
- ) ?
36
- . to_bstring ( ) ;
37
- assert_eq ! ( url, "~/path/to/git" ) ;
38
- Ok ( ( ) )
33
+ )
39
34
}
40
35
41
36
#[ test]
42
37
fn no_username_expansion_for_file_paths_with_protocol ( ) -> crate :: Result {
43
38
assert_url_roundtrip (
44
39
"file:///~username/path/to/git" ,
45
40
url ( Scheme :: File , None , None , None , b"/~username/path/to/git" ) ,
41
+ ) ?;
42
+ assert_url_roundtrip (
43
+ "file://~username/path/to/git" ,
44
+ url ( Scheme :: File , None , "~username" , None , b"/path/to/git" ) ,
46
45
)
47
46
}
48
47
49
48
#[ test]
50
49
fn non_utf8_file_path_without_protocol ( ) -> crate :: Result {
51
- let parsed = gix_url:: parse ( b"/path/to\xff /git" . as_bstr ( ) ) ?;
52
- assert_eq ! (
53
- parsed,
54
- url_alternate( Scheme :: File , None , None , None , b"/path/to\xff /git" , )
55
- ) ;
56
- let url_lossless = parsed. to_bstring ( ) ;
50
+ let url = gix_url:: parse ( b"/path/to\xff /git" . as_bstr ( ) ) ?;
51
+ assert_eq ! ( url, url_alternate( Scheme :: File , None , None , None , b"/path/to\xff /git" ) ) ;
52
+ let url_lossless = url. to_bstring ( ) ;
57
53
assert_eq ! (
58
54
url_lossless. to_string( ) ,
59
55
"/path/to�/git" ,
@@ -65,44 +61,30 @@ fn non_utf8_file_path_without_protocol() -> crate::Result {
65
61
66
62
#[ test]
67
63
fn relative_file_path_without_protocol ( ) -> crate :: Result {
68
- let parsed = assert_url (
64
+ assert_url_roundtrip (
69
65
"../../path/to/git" ,
70
66
url_alternate ( Scheme :: File , None , None , None , b"../../path/to/git" ) ,
71
- ) ?
72
- . to_bstring ( ) ;
73
- assert_eq ! ( parsed, "../../path/to/git" ) ;
74
- let url = assert_url (
67
+ ) ?;
68
+ assert_url_roundtrip (
75
69
"path/to/git" ,
76
70
url_alternate ( Scheme :: File , None , None , None , b"path/to/git" ) ,
77
- ) ?
78
- . to_bstring ( ) ;
79
- assert_eq ! ( url, "path/to/git" ) ;
80
- Ok ( ( ) )
71
+ )
81
72
}
82
73
83
74
#[ test]
84
75
fn shortest_possible_absolute_path ( ) -> crate :: Result {
85
- let parsed = assert_url ( "/" , url_alternate ( Scheme :: File , None , None , None , b"/" ) ) ?. to_bstring ( ) ;
86
- assert_eq ! ( parsed, "/" ) ;
87
- let parsed = assert_url ( "file:///" , url ( Scheme :: File , None , None , None , b"/" ) ) ?. to_bstring ( ) ;
88
- assert_eq ! ( parsed, "file:///" ) ;
89
- Ok ( ( ) )
76
+ assert_url_roundtrip ( "/" , url_alternate ( Scheme :: File , None , None , None , b"/" ) ) ?;
77
+ assert_url_roundtrip ( "file:///" , url ( Scheme :: File , None , None , None , b"/" ) )
90
78
}
91
79
92
80
#[ test]
93
81
fn shortest_possible_relative_path ( ) -> crate :: Result {
94
- let parsed = assert_url ( "a" , url_alternate ( Scheme :: File , None , None , None , b"a" ) ) ?. to_bstring ( ) ;
95
- assert_eq ! ( parsed, "a" ) ;
96
- let parsed = assert_url ( "../" , url_alternate ( Scheme :: File , None , None , None , b"../" ) ) ?. to_bstring ( ) ;
97
- assert_eq ! ( parsed, "../" ) ;
98
- let parsed = assert_url ( "..\\ " , url_alternate ( Scheme :: File , None , None , None , b"..\\ " ) ) ?. to_bstring ( ) ;
99
- assert_eq ! ( parsed, "..\\ " ) ;
100
- let parsed = assert_url ( "./" , url_alternate ( Scheme :: File , None , None , None , b"./" ) ) ?. to_bstring ( ) ;
101
- assert_eq ! ( parsed, "./" ) ;
102
- let parsed = assert_url ( "." , url_alternate ( Scheme :: File , None , None , None , b"." ) ) ?. to_bstring ( ) ;
103
- assert_eq ! ( parsed, "." ) ;
104
- let parsed = assert_url ( ".." , url_alternate ( Scheme :: File , None , None , None , b".." ) ) ?. to_bstring ( ) ;
105
- assert_eq ! ( parsed, ".." ) ;
82
+ assert_url_roundtrip ( "a" , url_alternate ( Scheme :: File , None , None , None , b"a" ) ) ?;
83
+ assert_url_roundtrip ( "../" , url_alternate ( Scheme :: File , None , None , None , b"../" ) ) ?;
84
+ assert_url_roundtrip ( "..\\ " , url_alternate ( Scheme :: File , None , None , None , b"..\\ " ) ) ?;
85
+ assert_url_roundtrip ( "./" , url_alternate ( Scheme :: File , None , None , None , b"./" ) ) ?;
86
+ assert_url_roundtrip ( "." , url_alternate ( Scheme :: File , None , None , None , b"." ) ) ?;
87
+ assert_url_roundtrip ( ".." , url_alternate ( Scheme :: File , None , None , None , b".." ) ) ?;
106
88
Ok ( ( ) )
107
89
}
108
90
@@ -111,29 +93,28 @@ fn no_relative_paths_if_protocol() -> crate::Result {
111
93
assert_url_roundtrip ( "file://../" , url ( Scheme :: File , None , ".." , None , b"/" ) ) ?;
112
94
assert_url_roundtrip ( "file://./" , url ( Scheme :: File , None , "." , None , b"/" ) ) ?;
113
95
assert_url_roundtrip ( "file://a/" , url ( Scheme :: File , None , "a" , None , b"/" ) ) ?;
96
+ assert_matches ! (
97
+ gix_url:: parse( "file://.\\ " . into( ) ) ,
98
+ Err ( gix_url:: parse:: Error :: MissingRepositoryPath { .. } ) ,
99
+ "DEVIATION: on windows, this parses with git into something nonesensical Diag: url=file://./ Diag: protocol=file Diag: hostandport=./ Diag: path=//./"
100
+ ) ;
114
101
Ok ( ( ) )
115
102
}
116
103
117
104
#[ test]
118
105
fn interior_relative_file_path_without_protocol ( ) -> crate :: Result {
119
- let url = assert_url (
106
+ assert_url_roundtrip (
120
107
"/abs/path/../../path/to/git" ,
121
108
url_alternate ( Scheme :: File , None , None , None , b"/abs/path/../../path/to/git" ) ,
122
- ) ?
123
- . to_bstring ( ) ;
124
- assert_eq ! ( url, "/abs/path/../../path/to/git" ) ;
125
- Ok ( ( ) )
109
+ )
126
110
}
127
111
128
112
#[ test]
129
113
fn url_from_relative_path_with_colon_in_name ( ) -> crate :: Result {
130
- let url = assert_url (
114
+ assert_url_roundtrip (
131
115
"./weird/directory/na:me" ,
132
116
url_alternate ( Scheme :: File , None , None , None , b"./weird/directory/na:me" ) ,
133
- ) ?
134
- . to_bstring ( ) ;
135
- assert_eq ! ( url, "./weird/directory/na:me" ) ;
136
- Ok ( ( ) )
117
+ )
137
118
}
138
119
139
120
#[ cfg( windows) ]
@@ -153,31 +134,25 @@ mod windows {
153
134
url_alternate ( Scheme :: File , None , None , None , b"C:\\ users\\ 1\\ " ) ,
154
135
) ?;
155
136
// A special hack to support URLs on windows that are prefixed with `/` even though absolute.
156
- assert_url ( "file:///c:/users/2" , url ( Scheme :: File , None , None , None , b"c:/users/2" ) ) ?;
157
- assert_url ( "file:/// c:/users/3" , url ( Scheme :: File , None , None , None , b"c:/users/3" ) ) ? ;
137
+ let url = assert_url ( "file:///c:/users/2" , url ( Scheme :: File , None , None , None , b"c:/users/2" ) ) ?;
138
+ assert_eq ! ( url . to_bstring ( ) , "file://c:/users/2" ) ;
158
139
Ok ( ( ) )
159
140
}
160
141
161
142
#[ test]
162
143
fn file_path_without_protocol ( ) -> crate :: Result {
163
- let url = assert_url (
144
+ assert_url_roundtrip (
164
145
"x:/path/to/git" ,
165
146
url_alternate ( Scheme :: File , None , None , None , b"x:/path/to/git" ) ,
166
- ) ?
167
- . to_bstring ( ) ;
168
- assert_eq ! ( url, "x:/path/to/git" ) ;
169
- Ok ( ( ) )
147
+ )
170
148
}
171
149
172
150
#[ test]
173
151
fn file_path_with_backslashes_without_protocol ( ) -> crate :: Result {
174
- let url = assert_url (
152
+ assert_url_roundtrip (
175
153
"x:\\ path\\ to\\ git" ,
176
154
url_alternate ( Scheme :: File , None , None , None , b"x:\\ path\\ to\\ git" ) ,
177
- ) ?
178
- . to_bstring ( ) ;
179
- assert_eq ! ( url, "x:\\ path\\ to\\ git" ) ;
180
- Ok ( ( ) )
155
+ )
181
156
}
182
157
183
158
#[ test]
@@ -191,43 +166,36 @@ mod windows {
191
166
192
167
#[ cfg( not( windows) ) ]
193
168
mod unix {
194
- use crate :: parse:: { assert_url , assert_url_roundtrip, url, url_alternate} ;
169
+ use crate :: parse:: { assert_url_roundtrip, url, url_alternate} ;
195
170
use gix_url:: Scheme ;
196
171
197
172
#[ test]
198
173
fn url_from_absolute_path ( ) -> crate :: Result {
199
- assert_url (
174
+ assert_url_roundtrip (
200
175
url:: Url :: from_directory_path ( "/users/foo" )
201
176
. expect ( "valid" )
202
177
. to_file_path ( )
203
178
. expect ( "valid path" )
204
179
. to_string_lossy ( )
205
180
. as_ref ( ) ,
206
181
url_alternate ( Scheme :: File , None , None , None , b"/users/foo/" ) ,
207
- ) ?;
208
- Ok ( ( ) )
182
+ )
209
183
}
210
184
211
185
#[ test]
212
186
fn file_path_without_protocol ( ) -> crate :: Result {
213
- let url = assert_url (
187
+ assert_url_roundtrip (
214
188
"x:/path/to/git" ,
215
189
url_alternate ( Scheme :: Ssh , None , "x" , None , b"/path/to/git" ) ,
216
- ) ?
217
- . to_bstring ( ) ;
218
- assert_eq ! ( url, "x:/path/to/git" ) ;
219
- Ok ( ( ) )
190
+ )
220
191
}
221
192
222
193
#[ test]
223
194
fn file_path_with_backslashes_without_protocol ( ) -> crate :: Result {
224
- let url = assert_url (
195
+ assert_url_roundtrip (
225
196
"x:\\ path\\ to\\ git" ,
226
197
url_alternate ( Scheme :: Ssh , None , "x" , None , b"\\ path\\ to\\ git" ) ,
227
- ) ?
228
- . to_bstring ( ) ;
229
- assert_eq ! ( url, "x:\\ path\\ to\\ git" ) ;
230
- Ok ( ( ) )
198
+ )
231
199
}
232
200
233
201
#[ test]
0 commit comments