From 3731ddb361163f3d6b86844362871e48c80fa530 Mon Sep 17 00:00:00 2001 From: Ceri Storey Date: Tue, 2 Feb 2016 17:57:02 +0000 Subject: [PATCH] fix(matched_arg): Allow for more than 256 occurrences of an argument. --- src/args/arg_matches.rs | 2 +- src/args/matched_arg.rs | 2 +- tests/multiple_occurrences.rs | 13 ++++++++++++- 3 files changed, 14 insertions(+), 3 deletions(-) diff --git a/src/args/arg_matches.rs b/src/args/arg_matches.rs index 79496746960..a574dcd7f76 100644 --- a/src/args/arg_matches.rs +++ b/src/args/arg_matches.rs @@ -326,7 +326,7 @@ impl<'a> ArgMatches<'a> { /// assert_eq!(m.occurrences_of("debug"), 3); /// assert_eq!(m.occurrences_of("flag"), 1); /// ``` - pub fn occurrences_of>(&self, name: S) -> u8 { + pub fn occurrences_of>(&self, name: S) -> u64 { self.args.get(name.as_ref()).map_or(0, |a| a.occurs) } diff --git a/src/args/matched_arg.rs b/src/args/matched_arg.rs index b572812daa4..df6f7ad9974 100644 --- a/src/args/matched_arg.rs +++ b/src/args/matched_arg.rs @@ -6,7 +6,7 @@ use vec_map::VecMap; #[derive(Debug, Clone)] pub struct MatchedArg { #[doc(hidden)] - pub occurs: u8, + pub occurs: u64, #[doc(hidden)] pub vals: VecMap, } diff --git a/tests/multiple_occurrences.rs b/tests/multiple_occurrences.rs index acbfcdae09b..6b31b7322fd 100644 --- a/tests/multiple_occurrences.rs +++ b/tests/multiple_occurrences.rs @@ -62,4 +62,15 @@ fn multiple_occurrences_of_flags_mixed() { assert_eq!(m.occurrences_of("multflag2"), 2); assert!(m.is_present("flag")); assert_eq!(m.occurrences_of("flag"), 1); -} \ No newline at end of file +} + +#[test] +fn multiple_occurrences_of_flags_large_quantity() { + let args : Vec<&str> = vec![""].into_iter().chain(vec!["-m"; 1024].into_iter()).collect(); + let m = App::new("multiple_occurrences") + .arg(Arg::from_usage("-m --multflag 'allowed multiple flag'") + .multiple(true)) + .get_matches_from(args); + assert!(m.is_present("multflag")); + assert_eq!(m.occurrences_of("multflag"), 1024); +}