From 8fe3a39994bdd95379ebd25afbb83889cded390f Mon Sep 17 00:00:00 2001 From: 魏曹先生 <1992414357@qq.com> Date: Thu, 16 Jul 2026 01:28:37 +0800 Subject: feat(parselib): apply naming case conversion to long flags and aliases --- mingling_picker/test/src/test/style_test.rs | 73 ++++++++++++++++++++++++++++- 1 file changed, 71 insertions(+), 2 deletions(-) (limited to 'mingling_picker/test') diff --git a/mingling_picker/test/src/test/style_test.rs b/mingling_picker/test/src/test/style_test.rs index 25a5081..795c4ab 100644 --- a/mingling_picker/test/src/test/style_test.rs +++ b/mingling_picker/test/src/test/style_test.rs @@ -1,6 +1,7 @@ use mingling_picker::PickerArgInfo; use mingling_picker::parselib::{ - MaskedArg, Matcher, POWERSHELL_STYLE, UNIX_STYLE, WINDOWS_STYLE, build_possible_flags, + MaskedArg, Matcher, POWERSHELL_STYLE, ParserStyle, ParserStyleNamingCase, UNIX_STYLE, + WINDOWS_STYLE, build_possible_flags, }; // Style: formatting utilities @@ -29,7 +30,7 @@ fn test_build_possible_flags_windows() { let mut info = PickerArgInfo::new(); info.set_long("verbose"); let flags = build_possible_flags(&WINDOWS_STYLE, &info); - assert_eq!(flags, vec!["/verbose"]); + assert_eq!(flags, vec!["/Verbose"]); } #[test] @@ -131,6 +132,7 @@ fn test_windows_style_match_all() { #[test] fn test_windows_style_match_after_end_of_options() { + // end_of_options is always "--" regardless of style // Flags after -- should not match let mut info = PickerArgInfo::new(); info.set_long("verbose"); @@ -144,3 +146,70 @@ fn test_windows_style_match_after_end_of_options() { // end_of_options is always "--" regardless of style assert_eq!(result, vec![0]); } + +// Naming case conversion + +/// A Unix-like style with kebab-case naming. +const KEBAB_STYLE: ParserStyle<'static> = ParserStyle { + naming_case: ParserStyleNamingCase::Kebab, + ..UNIX_STYLE +}; + +#[test] +fn test_kebab_case_naming_for_multiword_flag() { + // flag name `flag_a` → Kebab → `flag-a` → `--flag-a` + let mut info = PickerArgInfo::new(); + info.set_long("flag_a"); + + let args = vec![make_masked("--flag-a", 0)]; + let result = ::on_match_one(&args, &KEBAB_STYLE, &info); + assert_eq!( + result, + Some(0), + "--flag-a should match flag_a via kebab-case conversion" + ); +} + +#[test] +fn test_snake_case_should_not_match_as_long_flag() { + // With kebab naming, `--flag_a` (snake) should NOT match `flag_a` + let mut info = PickerArgInfo::new(); + info.set_long("flag_a"); + + let args = vec![make_masked("--flag_a", 0)]; + let result = ::on_match_one(&args, &KEBAB_STYLE, &info); + assert_eq!( + result, None, + "--flag_a should NOT match in kebab-style context" + ); +} + +#[test] +fn test_snake_case_naming_for_unix_style() { + // UNIX_STYLE uses snake case: `flag_a` stays `flag_a` → `--flag_a` + let mut info = PickerArgInfo::new(); + info.set_long("flag_a"); + + let args = vec![make_masked("--flag_a", 0)]; + let result = ::on_match_one(&args, &UNIX_STYLE, &info); + assert_eq!( + result, + Some(0), + "--flag_a should match with snake-style UNIX_STYLE" + ); +} + +#[test] +fn test_powershell_pascal_case_naming() { + // POWERSHELL_STYLE uses Pascal case: `verbose` → `Verbose` → `-Verbose` + let mut info = PickerArgInfo::new(); + info.set_long("verbose"); + + let args = vec![make_masked("-Verbose", 0)]; + let result = ::on_match_one(&args, &POWERSHELL_STYLE, &info); + assert_eq!( + result, + Some(0), + "-Verbose should match verbose via Pascal case" + ); +} -- cgit