about summary refs log tree commit diff
path: root/library/std/src/sys/windows/path
diff options
context:
space:
mode:
authorChristiaan Dirkx <christiaan@dirkx.email>2020-11-03 19:26:31 +0100
committerChristiaan Dirkx <christiaan@dirkx.email>2020-11-07 16:15:48 +0100
commit94d73d4403ef98b3b38b8e3035c2eac87fb900f9 (patch)
tree25f3a6e8a3d5156ea60b062ee287fa4c43caf99d /library/std/src/sys/windows/path
parenta601302ff0217b91589b5a7310a8a23adb843fdc (diff)
downloadrust-94d73d4403ef98b3b38b8e3035c2eac87fb900f9.tar.gz
rust-94d73d4403ef98b3b38b8e3035c2eac87fb900f9.zip
Refactor `parse_prefix` on Windows
Refactor `get_first_two_components` to `get_next_component`.

Fixes the following behaviour of `parse_prefix`:
 - series of separator bytes in a prefix are correctly parsed as a single separator
 - device namespace prefixes correctly recognize both `\\` and `/` as separators
Diffstat (limited to 'library/std/src/sys/windows/path')
-rw-r--r--library/std/src/sys/windows/path/tests.rs39
1 files changed, 31 insertions, 8 deletions
diff --git a/library/std/src/sys/windows/path/tests.rs b/library/std/src/sys/windows/path/tests.rs
index fbac1dc1ca1..9675da6ff88 100644
--- a/library/std/src/sys/windows/path/tests.rs
+++ b/library/std/src/sys/windows/path/tests.rs
@@ -1,21 +1,44 @@
 use super::*;
 
 #[test]
-fn test_get_first_two_components() {
+fn test_parse_next_component() {
     assert_eq!(
-        get_first_two_components(br"server\share", is_verbatim_sep),
-        Some((&b"server"[..], &b"share"[..])),
+        parse_next_component(OsStr::new(r"server\share"), true),
+        (OsStr::new(r"server"), OsStr::new(r"share"))
     );
 
     assert_eq!(
-        get_first_two_components(br"server\", is_verbatim_sep),
-        Some((&b"server"[..], &b""[..]))
+        parse_next_component(OsStr::new(r"server/share"), true),
+        (OsStr::new(r"server/share"), OsStr::new(r""))
     );
 
     assert_eq!(
-        get_first_two_components(br"\server\", is_verbatim_sep),
-        Some((&b""[..], &b"server"[..]))
+        parse_next_component(OsStr::new(r"server/share"), false),
+        (OsStr::new(r"server"), OsStr::new(r"share"))
     );
 
-    assert_eq!(get_first_two_components(br"there are no separators here", is_verbatim_sep), None,);
+    assert_eq!(
+        parse_next_component(OsStr::new(r"server\"), false),
+        (OsStr::new(r"server"), OsStr::new(r""))
+    );
+
+    assert_eq!(
+        parse_next_component(OsStr::new(r"\server\"), false),
+        (OsStr::new(r""), OsStr::new(r"server\"))
+    );
+
+    assert_eq!(
+        parse_next_component(OsStr::new(r"servershare"), false),
+        (OsStr::new(r"servershare"), OsStr::new(""))
+    );
+
+    assert_eq!(
+        parse_next_component(OsStr::new(r"server/\//\/\\\\/////\/share"), false),
+        (OsStr::new(r"server"), OsStr::new(r"share"))
+    );
+
+    assert_eq!(
+        parse_next_component(OsStr::new(r"server\\\\\\\\\\\\\\share"), true),
+        (OsStr::new(r"server"), OsStr::new(r"\\\\\\\\\\\\\share"))
+    );
 }