Files
wfassoc/wfassoc/tests/extra_windows.rs
yyc12345 23d0a79c0b feat(windows): add resource reference string parsers
Add IconRc and StrRc structs for parsing Windows resource reference strings.
Implement FromStr and Display traits for both types along with error handling.
Rename BadExpandStrError to ParseExpandStrError for consistency.
2025-10-24 10:34:07 +08:00

118 lines
2.6 KiB
Rust

use std::path::Path;
use wfassoc::extra::windows::*;
#[test]
fn test_icon_rc() {
}
#[test]
fn test_str_rc() {
}
#[test]
fn test_expand_string() {
}
#[test]
fn test_icon() {
fn tester(file: &str, index: i32) {
let icon = Icon::new(Path::new(file), index, IconSizeKind::Small);
assert!(icon.is_ok())
}
// We pick it from "jpegfile" ProgId
tester("imageres.dll", 72);
}
#[test]
fn test_cmd_args() {
// Declare tester
fn tester(s: &str, probe: &[&'static str]) {
let rv = CmdArgs::new(s);
let inner = rv.get_inner();
assert_eq!(inner.len(), probe.len());
let n = inner.len();
for i in 0..n {
assert_eq!(inner[i].get_inner(), probe[i]);
}
}
// Normal cases
tester(
"MyApp.exe --config ppic.toml",
&["MyApp.exe", "--config", "ppic.toml"],
);
tester(
r#""C:\Program Files\MyApp\MyApp.exe" --config ppic.toml"#,
&[
r#"C:\Program Files\MyApp\MyApp.exe"#,
"--config",
"ppic.toml",
],
);
// Microsoft shitty cases.
tester(r#""abc" d e"#, &[r#"abc"#, r#"d"#, r#"e"#]);
tester(r#"a\\b d"e f"g h"#, &[r#"a\\b"#, r#"de fg"#, r#"h"#]);
tester(r#"a\\\"b c d"#, &[r#"a\"b"#, r#"c"#, r#"d"#]);
tester(r#"a\\\\"b c" d e"#, &[r#"a\\b c"#, r#"d"#, r#"e"#]);
tester(r#"a"b"" c d"#, &[r#"ab" c d"#]);
}
#[test]
fn test_cmd_arg() {
// Declare tester
fn ok_tester(s: &str, probe: &str) {
let rv = CmdArg::new(s);
assert!(rv.is_ok());
let rv = rv.unwrap();
assert_eq!(rv.get_inner(), probe);
}
fn err_tester(s: &str) {
let rv = CmdArg::new(s);
assert!(rv.is_err());
}
// Normal test
ok_tester(
r#""C:\Program Files\MyApp\MyApp.exe""#,
r#"C:\Program Files\MyApp\MyApp.exe"#,
);
err_tester("MyApp.exe --config ppic.toml");
err_tester("");
}
#[test]
fn test_cmd_arg_quoted_string() {
fn tester(s: &str, probe: &str) {
let rv = CmdArg::with_inner(s);
assert_eq!(rv.to_quoted_string(true), probe);
}
tester(
r#"C:\Program Files\MyApp\MyApp.exe"#,
r#""C:\Program Files\MyApp\MyApp.exe""#,
);
}
#[test]
fn test_cmd_args_quoted_string() {
fn tester(args: &[&str], probe: &str) {
let rv = CmdArgs::with_inner(args.iter().map(|s| CmdArg::with_inner(s)));
assert_eq!(rv.to_quoted_string(), probe);
}
tester(
&[
r#"C:\Program Files\MyApp\MyApp.exe"#,
"--config",
"ppic.toml",
],
r#""C:\Program Files\MyApp\MyApp.exe" --config ppic.toml"#,
);
}