diff options
| author | Weicao-CatilGrass <1992414357@qq.com> | 2026-06-09 21:08:20 +0800 |
|---|---|---|
| committer | Weicao-CatilGrass <1992414357@qq.com> | 2026-06-09 22:23:16 +0800 |
| commit | 514929c3b8ee0d4f540be5eb4bc8c1a10e62095d (patch) | |
| tree | 8faeeb71075a695354496af38eb527085bb37f92 /mingling_core/src/program/flag.rs | |
| parent | 92cccd9517e764508dfa0342ae2ea254661d0a8f (diff) | |
Add unit and integration tests for mingling_core
Diffstat (limited to 'mingling_core/src/program/flag.rs')
| -rw-r--r-- | mingling_core/src/program/flag.rs | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/mingling_core/src/program/flag.rs b/mingling_core/src/program/flag.rs index bc1c922..0865414 100644 --- a/mingling_core/src/program/flag.rs +++ b/mingling_core/src/program/flag.rs @@ -161,6 +161,8 @@ macro_rules! special_arguments { #[cfg(test)] mod tests { + use crate::Flag; + #[test] fn test_special_flag() { // Test flag found and removed @@ -466,6 +468,57 @@ mod tests { assert_eq!(result, vec!["a", "b"]); assert_eq!(args, vec!["--next", "1"]); } + + #[test] + fn test_flag_from_empty_tuple() { + let flag = Flag::from(()); + assert_eq!(flag.as_ref(), &[] as &[&str]); + } + + #[test] + fn test_flag_from_static_str() { + let flag = Flag::from("-h"); + assert_eq!(flag.as_ref(), &["-h"]); + } + + #[test] + fn test_flag_from_slice() { + let flag = Flag::from(&["-h", "--help"][..]); + assert_eq!(flag.as_ref(), &["-h", "--help"]); + } + + #[test] + fn test_flag_from_array() { + let flag = Flag::from(["-v", "--verbose"]); + assert_eq!(flag.as_ref(), &["-v", "--verbose"]); + } + + #[test] + fn test_flag_from_ref_array() { + let flag = Flag::from(&["-f", "--file"]); + assert_eq!(flag.as_ref(), &["-f", "--file"]); + } + + #[test] + fn test_flag_from_ref_flag() { + let original = Flag::from("-x"); + let cloned = Flag::from(&original); + assert_eq!(cloned.as_ref(), &["-x"]); + } + + #[test] + fn test_flag_as_ref() { + let flag = Flag::from("-h"); + let r: &[&str] = flag.as_ref(); + assert_eq!(r, &["-h"]); + } + + #[test] + fn test_flag_deref() { + let flag = Flag::from(["-a", "-b"]); + let collected: Vec<&&str> = flag.iter().collect(); + assert_eq!(collected, vec![&"-a", &"-b"]); + } } impl<C> Program<C> |
