about summary refs log tree commit diff
path: root/library/std/src/sys/windows/args/tests.rs
diff options
context:
space:
mode:
authorLzu Tao <taolzu@gmail.com>2020-08-27 13:45:01 +0000
committerLzu Tao <taolzu@gmail.com>2020-08-31 02:56:59 +0000
commita4e926daeeaedc9178846711daf1f4cb6ce505fb (patch)
tree0c830f716f6f5ad17736d459f5de9b9199006d54 /library/std/src/sys/windows/args/tests.rs
parentdb6cbfc49ca655739ba8caae43ebd7c77c8a1179 (diff)
downloadrust-a4e926daeeaedc9178846711daf1f4cb6ce505fb.tar.gz
rust-a4e926daeeaedc9178846711daf1f4cb6ce505fb.zip
std: move "mod tests/benches" to separate files
Also doing fmt inplace as requested.
Diffstat (limited to 'library/std/src/sys/windows/args/tests.rs')
-rw-r--r--library/std/src/sys/windows/args/tests.rs61
1 files changed, 61 insertions, 0 deletions
diff --git a/library/std/src/sys/windows/args/tests.rs b/library/std/src/sys/windows/args/tests.rs
new file mode 100644
index 00000000000..756a4361ea3
--- /dev/null
+++ b/library/std/src/sys/windows/args/tests.rs
@@ -0,0 +1,61 @@
+use crate::ffi::OsString;
+use crate::sys::windows::args::*;
+
+fn chk(string: &str, parts: &[&str]) {
+    let mut wide: Vec<u16> = OsString::from(string).encode_wide().collect();
+    wide.push(0);
+    let parsed =
+        unsafe { parse_lp_cmd_line(wide.as_ptr() as *const u16, || OsString::from("TEST.EXE")) };
+    let expected: Vec<OsString> = parts.iter().map(|k| OsString::from(k)).collect();
+    assert_eq!(parsed.as_slice(), expected.as_slice());
+}
+
+#[test]
+fn empty() {
+    chk("", &["TEST.EXE"]);
+    chk("\0", &["TEST.EXE"]);
+}
+
+#[test]
+fn single_words() {
+    chk("EXE one_word", &["EXE", "one_word"]);
+    chk("EXE a", &["EXE", "a"]);
+    chk("EXE 😅", &["EXE", "😅"]);
+    chk("EXE 😅🤦", &["EXE", "😅🤦"]);
+}
+
+#[test]
+fn official_examples() {
+    chk(r#"EXE "abc" d e"#, &["EXE", "abc", "d", "e"]);
+    chk(r#"EXE a\\\b d"e f"g h"#, &["EXE", r#"a\\\b"#, "de fg", "h"]);
+    chk(r#"EXE a\\\"b c d"#, &["EXE", r#"a\"b"#, "c", "d"]);
+    chk(r#"EXE a\\\\"b c" d e"#, &["EXE", r#"a\\b c"#, "d", "e"]);
+}
+
+#[test]
+fn whitespace_behavior() {
+    chk(r#" test"#, &["", "test"]);
+    chk(r#"  test"#, &["", "test"]);
+    chk(r#" test test2"#, &["", "test", "test2"]);
+    chk(r#" test  test2"#, &["", "test", "test2"]);
+    chk(r#"test test2 "#, &["test", "test2"]);
+    chk(r#"test  test2 "#, &["test", "test2"]);
+    chk(r#"test "#, &["test"]);
+}
+
+#[test]
+fn genius_quotes() {
+    chk(r#"EXE "" """#, &["EXE", "", ""]);
+    chk(r#"EXE "" """"#, &["EXE", "", "\""]);
+    chk(
+        r#"EXE "this is """all""" in the same argument""#,
+        &["EXE", "this is \"all\" in the same argument"],
+    );
+    chk(r#"EXE "a"""#, &["EXE", "a\""]);
+    chk(r#"EXE "a"" a"#, &["EXE", "a\"", "a"]);
+    // quotes cannot be escaped in command names
+    chk(r#""EXE" check"#, &["EXE", "check"]);
+    chk(r#""EXE check""#, &["EXE check"]);
+    chk(r#""EXE """for""" check"#, &["EXE ", r#"for""#, "check"]);
+    chk(r#""EXE \"for\" check"#, &[r#"EXE \"#, r#"for""#, "check"]);
+}