]> git.lizzy.rs Git - rust.git/blob - library/std/src/sys/windows/process/tests.rs
Rollup merge of #81136 - Xavientois:io_reader_size_hint, r=cramertj
[rust.git] / library / std / src / sys / windows / process / tests.rs
1 use super::make_command_line;
2 use crate::ffi::{OsStr, OsString};
3
4 #[test]
5 fn test_make_command_line() {
6     fn test_wrapper(prog: &str, args: &[&str], force_quotes: bool) -> String {
7         let command_line = &make_command_line(
8             OsStr::new(prog),
9             &args.iter().map(|a| OsString::from(a)).collect::<Vec<OsString>>(),
10             force_quotes,
11         )
12         .unwrap();
13         String::from_utf16(command_line).unwrap()
14     }
15
16     assert_eq!(test_wrapper("prog", &["aaa", "bbb", "ccc"], false), "\"prog\" aaa bbb ccc");
17
18     assert_eq!(
19         test_wrapper("C:\\Program Files\\blah\\blah.exe", &["aaa"], false),
20         "\"C:\\Program Files\\blah\\blah.exe\" aaa"
21     );
22     assert_eq!(
23         test_wrapper("C:\\Program Files\\blah\\blah.exe", &["aaa", "v*"], false),
24         "\"C:\\Program Files\\blah\\blah.exe\" aaa v*"
25     );
26     assert_eq!(
27         test_wrapper("C:\\Program Files\\blah\\blah.exe", &["aaa", "v*"], true),
28         "\"C:\\Program Files\\blah\\blah.exe\" \"aaa\" \"v*\""
29     );
30     assert_eq!(
31         test_wrapper("C:\\Program Files\\test", &["aa\"bb"], false),
32         "\"C:\\Program Files\\test\" aa\\\"bb"
33     );
34     assert_eq!(test_wrapper("echo", &["a b c"], false), "\"echo\" \"a b c\"");
35     assert_eq!(
36         test_wrapper("echo", &["\" \\\" \\", "\\"], false),
37         "\"echo\" \"\\\" \\\\\\\" \\\\\" \\"
38     );
39     assert_eq!(
40         test_wrapper("\u{03c0}\u{042f}\u{97f3}\u{00e6}\u{221e}", &[], false),
41         "\"\u{03c0}\u{042f}\u{97f3}\u{00e6}\u{221e}\""
42     );
43 }