|
1 | | -use crate::parse::{assert_url, url}; |
| 1 | +use crate::parse::{assert_url_and, assert_url_roundtrip, url}; |
2 | 2 | use git_url::Protocol; |
3 | 3 |
|
4 | 4 | #[test] |
5 | 5 | fn file_path_with_protocol() -> crate::Result { |
6 | | - assert_url( |
| 6 | + assert_url_roundtrip( |
7 | 7 | "file:///path/to/git", |
8 | 8 | url(Protocol::File, None, None, None, b"/path/to/git"), |
9 | 9 | ) |
10 | 10 | } |
11 | 11 |
|
12 | 12 | #[test] |
13 | 13 | fn file_path_without_protocol() -> crate::Result { |
14 | | - assert_url("/path/to/git", url(Protocol::File, None, None, None, b"/path/to/git")) |
| 14 | + let url = assert_url_and("/path/to/git", url(Protocol::File, None, None, None, b"/path/to/git"))?.to_string(); |
| 15 | + assert_eq!(url, "file:///path/to/git"); |
| 16 | + Ok(()) |
15 | 17 | } |
16 | 18 |
|
17 | 19 | #[test] |
18 | 20 | fn no_username_expansion_for_file_paths_without_protocol() -> crate::Result { |
19 | | - assert_url("~/path/to/git", url(Protocol::File, None, None, None, b"~/path/to/git")) |
| 21 | + let url = assert_url_and("~/path/to/git", url(Protocol::File, None, None, None, b"~/path/to/git"))?.to_string(); |
| 22 | + assert_eq!(url, "file://~/path/to/git"); |
| 23 | + Ok(()) |
20 | 24 | } |
21 | 25 | #[test] |
22 | 26 | fn no_username_expansion_for_file_paths_with_protocol() -> crate::Result { |
23 | | - assert_url( |
| 27 | + assert_url_roundtrip( |
24 | 28 | "file://~username/path/to/git", |
25 | 29 | url(Protocol::File, None, None, None, b"~username/path/to/git"), |
26 | 30 | ) |
27 | 31 | } |
28 | 32 |
|
29 | 33 | #[test] |
30 | 34 | fn non_utf8_file_path_without_protocol() -> crate::Result { |
| 35 | + let parsed = git_url::parse(b"/path/to\xff/git")?; |
| 36 | + assert_eq!(parsed, url(Protocol::File, None, None, None, b"/path/to\xff/git",)); |
31 | 37 | assert_eq!( |
32 | | - git_url::parse(b"/path/to\xff/git")?, |
33 | | - url(Protocol::File, None, None, None, b"/path/to\xff/git",) |
| 38 | + parsed.to_string(), |
| 39 | + "file:///path/to�/git", |
| 40 | + "non-unicode is made unicode safe" |
34 | 41 | ); |
35 | 42 | Ok(()) |
36 | 43 | } |
37 | 44 |
|
38 | 45 | #[test] |
39 | 46 | fn relative_file_path_without_protocol() -> crate::Result { |
40 | | - assert_url( |
| 47 | + let parsed = assert_url_and( |
41 | 48 | "../../path/to/git", |
42 | 49 | url(Protocol::File, None, None, None, b"../../path/to/git"), |
43 | | - )?; |
44 | | - assert_url("path/to/git", url(Protocol::File, None, None, None, b"path/to/git")) |
| 50 | + )? |
| 51 | + .to_string(); |
| 52 | + assert_eq!(parsed, "file://../../path/to/git"); |
| 53 | + let url = assert_url_and("path/to/git", url(Protocol::File, None, None, None, b"path/to/git"))?.to_string(); |
| 54 | + assert_eq!(url, "file://path/to/git"); |
| 55 | + Ok(()) |
45 | 56 | } |
46 | 57 |
|
47 | 58 | #[test] |
48 | 59 | fn interior_relative_file_path_without_protocol() -> crate::Result { |
49 | | - assert_url( |
| 60 | + let url = assert_url_and( |
50 | 61 | "/abs/path/../../path/to/git", |
51 | 62 | url(Protocol::File, None, None, None, b"/abs/path/../../path/to/git"), |
52 | | - ) |
| 63 | + )? |
| 64 | + .to_string(); |
| 65 | + assert_eq!(url, "file:///abs/path/../../path/to/git"); |
| 66 | + Ok(()) |
53 | 67 | } |
54 | 68 |
|
55 | 69 | mod windows { |
56 | | - use crate::parse::{assert_url, url}; |
| 70 | + use crate::parse::{assert_url_and, assert_url_roundtrip, url}; |
57 | 71 | use git_url::Protocol; |
58 | 72 |
|
59 | 73 | #[test] |
60 | 74 | fn file_path_without_protocol() -> crate::Result { |
61 | | - assert_url( |
| 75 | + let url = assert_url_and( |
62 | 76 | "x:/path/to/git", |
63 | 77 | url(Protocol::File, None, None, None, b"x:/path/to/git"), |
64 | | - ) |
| 78 | + )? |
| 79 | + .to_string(); |
| 80 | + assert_eq!(url, "file://x:/path/to/git"); |
| 81 | + Ok(()) |
65 | 82 | } |
66 | 83 |
|
67 | 84 | #[test] |
68 | 85 | fn file_path_with_backslashes_without_protocol() -> crate::Result { |
69 | | - assert_url( |
| 86 | + let url = assert_url_and( |
70 | 87 | "x:\\path\\to\\git", |
71 | 88 | url(Protocol::File, None, None, None, b"x:\\path\\to\\git"), |
72 | | - ) |
| 89 | + )? |
| 90 | + .to_string(); |
| 91 | + assert_eq!(url, "file://x:\\path\\to\\git"); |
| 92 | + Ok(()) |
73 | 93 | } |
74 | 94 |
|
75 | 95 | #[test] |
76 | 96 | fn file_path_with_protocol() -> crate::Result { |
77 | | - assert_url( |
| 97 | + assert_url_roundtrip( |
78 | 98 | "file://x:/path/to/git", |
79 | 99 | url(Protocol::File, None, None, None, b"x:/path/to/git"), |
80 | 100 | ) |
|
0 commit comments