aboutsummaryrefslogtreecommitdiff
path: root/mingling_picker/test/src
diff options
context:
space:
mode:
author魏曹先生 <1992414357@qq.com>2026-07-16 01:17:27 +0800
committer魏曹先生 <1992414357@qq.com>2026-07-16 01:17:27 +0800
commit3df0d61a2430f724382bdf06d1c577ac06f6e276 (patch)
tree04e6573f4c894132f47702370a725d917bd74515 /mingling_picker/test/src
parent3acf9cbdf292bf7724a9d208b887dc8dabf3e689 (diff)
test: add multi-style flag parsing tests
Add comprehensive test coverage for Windows, PowerShell, and UNIX style flag matching, including case sensitivity and end-of-options behavior
Diffstat (limited to 'mingling_picker/test/src')
-rw-r--r--mingling_picker/test/src/test.rs147
1 files changed, 146 insertions, 1 deletions
diff --git a/mingling_picker/test/src/test.rs b/mingling_picker/test/src/test.rs
index d5349d0..7c2a3cd 100644
--- a/mingling_picker/test/src/test.rs
+++ b/mingling_picker/test/src/test.rs
@@ -1,4 +1,7 @@
-use mingling_picker::{IntoPicker, macros::flag};
+use mingling_picker::parselib::{
+ MaskedArg, Matcher, POWERSHELL_STYLE, UNIX_STYLE, WINDOWS_STYLE, build_possible_flags,
+};
+use mingling_picker::{IntoPicker, PickerArgInfo, macros::flag};
// Basic bool flag — present / absent
@@ -420,3 +423,145 @@ fn test_with_route_type_switch() {
// The second flag is missing and has or_route → Err(-1)
assert_eq!(result, Err(-1));
}
+
+// Style: formatting utilities
+
+#[test]
+fn test_unix_style_flag_string() {
+ assert_eq!(UNIX_STYLE.flag_string('v'), "-v");
+ assert_eq!(UNIX_STYLE.flag_string("verbose"), "--verbose");
+}
+
+#[test]
+fn test_windows_style_flag_string() {
+ assert_eq!(WINDOWS_STYLE.flag_string('v'), "/v");
+ assert_eq!(WINDOWS_STYLE.flag_string("verbose"), "/verbose");
+}
+
+#[test]
+fn test_powershell_style_flag_string() {
+ assert_eq!(POWERSHELL_STYLE.flag_string('v'), "-v");
+ assert_eq!(POWERSHELL_STYLE.flag_string("Verbose"), "-Verbose");
+}
+
+#[test]
+fn test_build_possible_flags_windows() {
+ // Build PickerArgInfo from a flag definition: `verbose: bool`
+ let mut info = PickerArgInfo::new();
+ info.set_long("verbose");
+ let flags = build_possible_flags(&WINDOWS_STYLE, &info);
+ assert_eq!(flags, vec!["/verbose"]);
+}
+
+#[test]
+fn test_build_possible_flags_with_short_and_alias() {
+ let mut info = PickerArgInfo::new();
+ info.set_short('n');
+ info.set_long("name");
+ info.set_alias(vec!["nickname"]);
+ let flags = build_possible_flags(&UNIX_STYLE, &info);
+ assert_eq!(flags, vec!["-n", "--name", "--nickname"]);
+}
+
+// Style: matching with different styles via Matcher trait
+
+fn make_masked(raw: &str, idx: usize) -> MaskedArg<'_> {
+ MaskedArg { raw, raw_idx: idx }
+}
+
+#[test]
+fn test_windows_style_match() {
+ // Windows style: /verbose (case insensitive)
+ let mut info = PickerArgInfo::new();
+ info.set_long("verbose");
+
+ let args = vec![make_masked("/verbose", 0)];
+ let result = <bool as Matcher>::on_match_one(&args, &WINDOWS_STYLE, &info);
+ assert_eq!(result, Some(0));
+}
+
+#[test]
+fn test_windows_style_match_case_insensitive() {
+ // Windows style is case-insensitive: /VERBOSE should match "verbose"
+ let mut info = PickerArgInfo::new();
+ info.set_long("verbose");
+
+ let args = vec![make_masked("/VERBOSE", 0)];
+ let result = <bool as Matcher>::on_match_one(&args, &WINDOWS_STYLE, &info);
+ assert_eq!(result, Some(0));
+}
+
+#[test]
+fn test_windows_style_no_match_on_unrelated_flag() {
+ // Different flag should not match
+ let mut info = PickerArgInfo::new();
+ info.set_long("verbose");
+
+ let args = vec![make_masked("/output", 0)];
+ let result = <bool as Matcher>::on_match_one(&args, &WINDOWS_STYLE, &info);
+ assert_eq!(result, None);
+}
+
+#[test]
+fn test_powershell_style_match() {
+ // PowerShell style: -Verbose (case insensitive)
+ let mut info = PickerArgInfo::new();
+ info.set_long("Verbose");
+
+ let args = vec![make_masked("-Verbose", 0)];
+ let result = <bool as Matcher>::on_match_one(&args, &POWERSHELL_STYLE, &info);
+ assert_eq!(result, Some(0));
+}
+
+#[test]
+fn test_powershell_style_match_case_insensitive() {
+ let mut info = PickerArgInfo::new();
+ info.set_long("Verbose");
+
+ let args = vec![make_masked("-VERBOSE", 0)];
+ let result = <bool as Matcher>::on_match_one(&args, &POWERSHELL_STYLE, &info);
+ assert_eq!(result, Some(0));
+}
+
+#[test]
+fn test_unix_style_case_sensitive_no_match() {
+ // UNIX style is case-sensitive: --VERBOSE should NOT match --verbose
+ let mut info = PickerArgInfo::new();
+ info.set_long("verbose");
+
+ let args = vec![make_masked("--VERBOSE", 0)];
+ let result = <bool as Matcher>::on_match_one(&args, &UNIX_STYLE, &info);
+ assert_eq!(result, None);
+}
+
+#[test]
+fn test_windows_style_match_all() {
+ // on_match_all should find all matching flags
+ let mut info = PickerArgInfo::new();
+ info.set_long("verbose");
+ info.set_short('v');
+
+ let args = vec![
+ make_masked("/v", 0),
+ make_masked("/output", 1),
+ make_masked("/VERBOSE", 2),
+ ];
+ let result = <bool as Matcher>::on_match_all(&args, &WINDOWS_STYLE, &info);
+ assert_eq!(result, vec![0, 2]);
+}
+
+#[test]
+fn test_windows_style_match_after_end_of_options() {
+ // Flags after -- should not match
+ let mut info = PickerArgInfo::new();
+ info.set_long("verbose");
+
+ let args = vec![
+ make_masked("/verbose", 0),
+ make_masked("--", 1),
+ make_masked("/verbose", 2),
+ ];
+ let result = <bool as Matcher>::on_match_all(&args, &WINDOWS_STYLE, &info);
+ // end_of_options is always "--" regardless of style
+ assert_eq!(result, vec![0]);
+}