Skip to content

Commit 58e49d2

Browse files
committed
Use raw string literals for paths with backslashes
1 parent b4e1a78 commit 58e49d2

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

gix-fs/tests/stack/mod.rs

+29-29
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ fn path_join_handling() {
4040
looks_absolute.is_relative(),
4141
"on Windows, 'absolute' Linux paths are relative (and relative to the current drive)"
4242
);
43-
let bs_looks_absolute = p("\\absolute");
43+
let bs_looks_absolute = p(r"\absolute");
4444
assert!(
4545
bs_looks_absolute.is_relative(),
4646
"on Windows, strange single-backslash paths are relative (and relative to the current drive)"
@@ -62,29 +62,29 @@ fn path_join_handling() {
6262
"drive + relative = relative to the drive-specific current directory"
6363
);
6464
assert_eq!(
65-
p("c:\\").join("relative"),
66-
p("c:\\relative"),
65+
p(r"c:\").join("relative"),
66+
p(r"c:\relative"),
6767
"absolute + relative = joined result"
6868
);
6969

7070
assert_eq!(
71-
p("\\\\?\\base").join(looks_absolute),
72-
p("\\\\?\\base\\absolute"),
71+
p(r"\\?\base").join(looks_absolute),
72+
p(r"\\?\base\absolute"),
7373
"absolute1 + unix-absolute2 = joined result with backslash"
7474
);
7575
assert_eq!(
76-
p("\\\\.\\base").join(looks_absolute),
77-
p("\\\\.\\base\\absolute"),
76+
p(r"\\.\base").join(looks_absolute),
77+
p(r"\\.\base\absolute"),
7878
"absolute1 + absolute2 = joined result with backslash (device namespace)"
7979
);
8080
assert_eq!(
81-
p("\\\\?\\base").join(bs_looks_absolute),
82-
p("\\\\?\\base\\absolute"),
81+
p(r"\\?\base").join(bs_looks_absolute),
82+
p(r"\\?\base\absolute"),
8383
"absolute1 + absolute2 = joined result"
8484
);
8585
assert_eq!(
86-
p("\\\\.\\base").join(bs_looks_absolute),
87-
p("\\\\.\\base\\absolute"),
86+
p(r"\\.\base").join(bs_looks_absolute),
87+
p(r"\\.\base\absolute"),
8888
"absolute1 + absolute2 = joined result (device namespace)"
8989
);
9090

@@ -95,36 +95,36 @@ fn path_join_handling() {
9595
"d-drive + c-drive-relative = c-drive-relative - C: is relative but not on D:"
9696
);
9797
assert_eq!(
98-
p("d:\\").join("C:\\"),
99-
p("C:\\"),
98+
p(r"d:\").join(r"C:\"),
99+
p(r"C:\"),
100100
"d-drive-with-bs + c-drive-with-bs = c-drive-with-bs - nothing special happens with backslashes"
101101
);
102102
assert_eq!(
103-
p("c:\\").join("\\\\.\\"),
104-
p("\\\\.\\"),
103+
p(r"c:\").join(r"\\.\"),
104+
p(r"\\.\"),
105105
"c-drive-with-bs + device-namespace-unc = device-namespace-unc"
106106
);
107107
assert_eq!(
108108
p("/").join("C:/"),
109-
p("C:\\"),
109+
p(r"C:\"),
110110
"unix-absolute + win-drive = win-drive, strangely enough it changed the trailing slash to backslash, so better not have trailing slashes"
111111
);
112-
assert_eq!(p("/").join("C:\\"), p("C:\\"), "unix-absolute + win-drive = win-drive");
112+
assert_eq!(p("/").join(r"C:\"), p(r"C:\"), "unix-absolute + win-drive = win-drive");
113113
assert_eq!(
114-
p("\\\\.").join("C:"),
114+
p(r"\\.").join("C:"),
115115
p("C:"),
116-
"device-namespace-unc + win-drive-relative = win-drive-relative - C: as a relative path is not the C: device, so this is not \\\\.\\C:"
116+
r"device-namespace-unc + win-drive-relative = win-drive-relative - C: as a relative path is not the C: device, so this is not \\.\C:"
117117
);
118118
assert_eq!(p("relative").join("C:"), p("C:"), "relative + win-drive = win-drive");
119119

120120
assert_eq!(
121-
p("/").join("\\\\localhost"),
122-
p("\\localhost"),
121+
p("/").join(r"\\localhost"),
122+
p(r"\localhost"),
123123
"unix-absolute + win-absolute-unc-host = strangely, single-backslashed host"
124124
);
125125
assert_eq!(
126-
p("relative").join("\\\\localhost"),
127-
p("\\\\localhost"),
126+
p("relative").join(r"\\localhost"),
127+
p(r"\\localhost"),
128128
"relative + win-absolute-unc-host = win-absolute-unc-host"
129129
);
130130
}
@@ -154,8 +154,8 @@ fn path_join_handling() {
154154
assert_eq!(p("/").join("C:"), p("/C:"), "absolute + win-drive = joined result");
155155
assert_eq!(p("/").join("C:/"), p("/C:/"), "absolute + win-absolute = joined result");
156156
assert_eq!(
157-
p("/").join("C:\\"),
158-
p("/C:\\"),
157+
p("/").join(r"C:\"),
158+
p(r"/C:\"),
159159
"absolute + win-absolute = joined result"
160160
);
161161
assert_eq!(
@@ -165,13 +165,13 @@ fn path_join_handling() {
165165
);
166166

167167
assert_eq!(
168-
p("/").join("\\\\localhost"),
169-
p("/\\\\localhost"),
168+
p("/").join(r"\\localhost"),
169+
p(r"/\\localhost"),
170170
"absolute + win-absolute-unc-host = joined result"
171171
);
172172
assert_eq!(
173-
p("relative").join("\\\\localhost"),
174-
p("relative/\\\\localhost"),
173+
p("relative").join(r"\\localhost"),
174+
p(r"relative/\\localhost"),
175175
"relative + win-absolute-unc-host = joined result"
176176
);
177177
}

0 commit comments

Comments
 (0)