From 1d6a7c6e7e6aadc527346aa822f19d8587f714f3 Mon Sep 17 00:00:00 2001 From: tormol Date: Fri, 30 Sep 2016 13:47:47 +0200 Subject: [PATCH 1/4] fix(UsageParser): Handle non-ascii names / options. This should also speeds up the parser (except maybe for short options). Multi-codepoint characters still can't be used as short options, but people shouldn't non-ASCII options nyway. Closes #664 --- src/usage_parser.rs | 116 +++++++++++++++++++++++++------------------- 1 file changed, 67 insertions(+), 49 deletions(-) diff --git a/src/usage_parser.rs b/src/usage_parser.rs index b8344265e90..e33ea0087c0 100644 --- a/src/usage_parser.rs +++ b/src/usage_parser.rs @@ -52,14 +52,12 @@ impl<'a> UsageParser<'a> { loop { debugln!("iter; pos={};", self.pos); self.stop_at(token); - if self.pos < self.usage.len() { - if let Some(c) = self.usage.chars().nth(self.pos) { - match c { - '-' => self.short_or_long(&mut arg), - '.' => self.multiple(&mut arg), - '\'' => self.help(&mut arg), - _ => self.name(&mut arg), - } + if let Some(&c) = self.usage.as_bytes().get(self.pos) { + match c { + b'-' => self.short_or_long(&mut arg), + b'.' => self.multiple(&mut arg), + b'\'' => self.help(&mut arg), + _ => self.name(&mut arg), } } else { break; @@ -82,7 +80,7 @@ impl<'a> UsageParser<'a> { fn name(&mut self, arg: &mut Arg<'a, 'a>) { debugln!("fn=name;"); - if self.usage.chars().nth(self.pos).expect(INTERNAL_ERROR_MSG) == '<' && + if *self.usage.as_bytes().get(self.pos).expect(INTERNAL_ERROR_MSG) == b'<' && !self.explicit_name_set { arg.setb(ArgSettings::Required); } @@ -113,23 +111,17 @@ impl<'a> UsageParser<'a> { } fn stop_at(&mut self, f: F) - where F: Fn(u32) -> bool + where F: Fn(u8) -> bool { debugln!("fn=stop_at;"); self.start = self.pos; - for c in self.usage[self.start..].chars() { - if f(c as u32) { - self.pos += 1; - continue; - } - break; - } + self.pos += self.usage[self.start..].bytes().take_while(|&b| f(b) ).count(); } fn short_or_long(&mut self, arg: &mut Arg<'a, 'a>) { debugln!("fn=short_or_long;"); self.pos += 1; - if self.usage.chars().nth(self.pos).expect(INTERNAL_ERROR_MSG) == '-' { + if *self.usage.as_bytes().get(self.pos).expect(INTERNAL_ERROR_MSG) == b'-' { self.pos += 1; self.long(arg); return; @@ -141,7 +133,7 @@ impl<'a> UsageParser<'a> { debugln!("fn=long;"); self.stop_at(long_end); let name = &self.usage[self.start..self.pos]; - if arg.name.is_empty() || (self.prev == UsageToken::Short && arg.name.len() == 1) { + if !self.explicit_name_set { debugln!("setting name: {}", name); arg.name = name; } @@ -152,41 +144,41 @@ impl<'a> UsageParser<'a> { fn short(&mut self, arg: &mut Arg<'a, 'a>) { debugln!("fn=short;"); - let name = &self.usage[self.pos..self.pos + 1]; - debugln!("setting short: {}", name); - arg.short = Some(name.chars().nth(0).expect(INTERNAL_ERROR_MSG)); + let start = &self.usage[self.pos..]; + let short = start.chars().nth(0).expect(INTERNAL_ERROR_MSG); + debugln!("setting short: {}", short); + arg.short = Some(short); if arg.name.is_empty() { + // --long takes precedence but doesn't set self.explicit_name_set + let name = &start[..short.len_utf8()]; debugln!("setting name: {}", name); arg.name = name; } self.prev = UsageToken::Short; } + // "something..." fn multiple(&mut self, arg: &mut Arg) { debugln!("fn=multiple;"); let mut dot_counter = 1; let start = self.pos; - for c in self.usage[start..].chars() { - match c { - '.' => { - dot_counter += 1; - self.pos += 1; - if dot_counter == 3 { - debugln!("setting multiple"); - arg.setb(ArgSettings::Multiple); - if arg.settings.is_set(ArgSettings::TakesValue) { - arg.setb(ArgSettings::UseValueDelimiter); - arg.unsetb(ArgSettings::ValueDelimiterNotSet); - if arg.val_delim.is_none() { - arg.val_delim = Some(','); - } - } - self.prev = UsageToken::Multiple; - self.pos += 1; - break; + let mut bytes = self.usage[start..].bytes(); + while bytes.next() == Some(b'.') { + dot_counter += 1; + self.pos += 1; + if dot_counter == 3 { + debugln!("setting multiple"); + arg.setb(ArgSettings::Multiple); + if arg.settings.is_set(ArgSettings::TakesValue) { + arg.setb(ArgSettings::UseValueDelimiter); + arg.unsetb(ArgSettings::ValueDelimiterNotSet); + if arg.val_delim.is_none() { + arg.val_delim = Some(','); } } - _ => break, + self.prev = UsageToken::Multiple; + self.pos += 1; + break; } } } @@ -204,26 +196,26 @@ impl<'a> UsageParser<'a> { } #[inline] -fn name_end(b: u32) -> bool { +fn name_end(b: u8) -> bool { // 93(]), 62(>) - b > b']' as u32 || b < b'>' as u32 || (b > b'>' as u32 && b < b']' as u32) + b > b']' || b < b'>' || (b > b'>' && b < b']') } #[inline] -fn token(b: u32) -> bool { +fn token(b: u8) -> bool { // 39('), 45(-), 46(.), 60(<), 91([) - b < 39 || b > 91 || (b > 46 && b < 91 && b != b'<' as u32) || (b > 39 && b < 45) + b < 39 || b > 91 || (b > 46 && b < 91 && b != b'<') || (b > 39 && b < 45) } #[inline] -fn long_end(b: u32) -> bool { - // 39('), 46(.), 60(<), 61(=), 91([) - (b < 39 && (b > 13 && b != b' ' as u32)) || b > 91 || (b > 61 && b < 91) || +fn long_end(b: u8) -> bool { + // 39('), 46(.), 60(<), 61(=), 91([), 32( ) + (b < 39 && (b > 13 && b != b' ')) || b > 91 || (b > 61 && b < 91) || (b > 39 && b < 60 && b != 46) } #[inline] -fn help_start(b: u32) -> bool { +fn help_start(b: u8) -> bool { // 39(') b < 39 || b > 39 } @@ -1220,4 +1212,30 @@ mod test { assert!(c.val_names.is_none()); assert!(c.num_vals.is_none()); } + + #[test] + fn nonascii() { + let a = Arg::from_usage(" 'üñíčöĐ€'"); + assert_eq!(a.name, "ASCII"); + assert_eq!(a.help, Some("üñíčöĐ€")); + let a = Arg::from_usage("<üñíčöĐ€> 'ASCII'"); + assert_eq!(a.name, "üñíčöĐ€"); + assert_eq!(a.help, Some("ASCII")); + let a = Arg::from_usage("<üñíčöĐ€> 'üñíčöĐ€'"); + assert_eq!(a.name, "üñíčöĐ€"); + assert_eq!(a.help, Some("üñíčöĐ€")); + let a = Arg::from_usage("-ø 'ø'"); + assert_eq!(a.name, "ø"); + assert_eq!(a.short, Some('ø')); + assert_eq!(a.help, Some("ø")); + let a = Arg::from_usage("--üñíčöĐ€ 'Nōṫ ASCII'"); + assert_eq!(a.name, "üñíčöĐ€"); + assert_eq!(a.long, Some("üñíčöĐ€")); + assert_eq!(a.help, Some("Nōṫ ASCII")); + let a = Arg::from_usage("[ñämê] --ôpt=[üñíčöĐ€] 'hælp'"); + assert_eq!(a.name, "ñämê"); + assert_eq!(a.long, Some("ôpt")); + assert_eq!(a.val_names.unwrap().values().collect::>(), [&"üñíčöĐ€"]); + assert_eq!(a.help, Some("hælp")); + } } From bb1fa0d694d926316784cc920c34f8590f00a602 Mon Sep 17 00:00:00 2001 From: tormol Date: Fri, 30 Sep 2016 13:48:37 +0200 Subject: [PATCH 2/4] refactor(UsageParser) Make the functions passed to .stop_at() straightforward --- src/usage_parser.rs | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/src/usage_parser.rs b/src/usage_parser.rs index e33ea0087c0..a8e2c73728d 100644 --- a/src/usage_parser.rs +++ b/src/usage_parser.rs @@ -197,27 +197,22 @@ impl<'a> UsageParser<'a> { #[inline] fn name_end(b: u8) -> bool { - // 93(]), 62(>) - b > b']' || b < b'>' || (b > b'>' && b < b']') + b != b']' && b != b'>' } #[inline] fn token(b: u8) -> bool { - // 39('), 45(-), 46(.), 60(<), 91([) - b < 39 || b > 91 || (b > 46 && b < 91 && b != b'<') || (b > 39 && b < 45) + b != b'\'' && b != b'.' && b != b'<' && b != b'[' && b != b'-' } #[inline] fn long_end(b: u8) -> bool { - // 39('), 46(.), 60(<), 61(=), 91([), 32( ) - (b < 39 && (b > 13 && b != b' ')) || b > 91 || (b > 61 && b < 91) || - (b > 39 && b < 60 && b != 46) + b != b'\'' && b != b'.' && b != b'<' && b != b'[' && b != b'=' && b != b' ' } #[inline] fn help_start(b: u8) -> bool { - // 39(') - b < 39 || b > 39 + b != b'\'' } #[cfg(test)] From 42a6d232d4a8557d0030fd4b5595d8f0de605276 Mon Sep 17 00:00:00 2001 From: tormol Date: Fri, 30 Sep 2016 15:30:31 +0200 Subject: [PATCH 3/4] refactor(UsageParser::parse) merge two ifs --- src/usage_parser.rs | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/src/usage_parser.rs b/src/usage_parser.rs index a8e2c73728d..7af822105bf 100644 --- a/src/usage_parser.rs +++ b/src/usage_parser.rs @@ -66,14 +66,10 @@ impl<'a> UsageParser<'a> { debug_assert!(!arg.name.is_empty(), format!("No name found for Arg when parsing usage string: {}", self.usage)); - let n_vals = if let Some(ref v) = arg.val_names { - v.len() - } else { - 0 + arg.num_vals = match arg.val_names { + Some(ref v) if v.len() >= 2 => Some(v.len() as u64), + _ => None, }; - if n_vals > 1 { - arg.num_vals = Some(n_vals as u64); - } debugln!("vals: {:?}", arg.val_names); arg } From fd4c0870bef23c57f5f5b00203550c69f40ba4c6 Mon Sep 17 00:00:00 2001 From: tormol Date: Fri, 30 Sep 2016 14:03:53 +0200 Subject: [PATCH 4/4] refactor(UsageParser tests) Use VecMap's .values() instead of .iter().map(|(_,&v)| v) In many cases this makes the assert fit on one line, but the double references are a bit awkward. --- src/usage_parser.rs | 173 +++++++++++++++++++------------------------- 1 file changed, 73 insertions(+), 100 deletions(-) diff --git a/src/usage_parser.rs b/src/usage_parser.rs index 7af822105bf..7c6807c8eed 100644 --- a/src/usage_parser.rs +++ b/src/usage_parser.rs @@ -341,8 +341,7 @@ mod test { assert!(!a.is_set(ArgSettings::Multiple)); assert!(a.is_set(ArgSettings::TakesValue)); assert!(!a.is_set(ArgSettings::Required)); - assert_eq!(a.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(a.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(a.num_vals.is_none()); } @@ -356,8 +355,7 @@ mod test { assert!(!b.is_set(ArgSettings::Multiple)); assert!(b.is_set(ArgSettings::TakesValue)); assert!(!b.is_set(ArgSettings::Required)); - assert_eq!(b.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(b.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(b.num_vals.is_none()); } @@ -371,8 +369,7 @@ mod test { assert!(!c.is_set(ArgSettings::Multiple)); assert!(c.is_set(ArgSettings::TakesValue)); assert!(c.is_set(ArgSettings::Required)); - assert_eq!(c.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(c.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(c.num_vals.is_none()); } @@ -386,8 +383,7 @@ mod test { assert!(!d.is_set(ArgSettings::Multiple)); assert!(d.is_set(ArgSettings::TakesValue)); assert!(d.is_set(ArgSettings::Required)); - assert_eq!(d.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(d.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(d.num_vals.is_none()); } @@ -401,8 +397,7 @@ mod test { assert!(a.is_set(ArgSettings::Multiple)); assert!(a.is_set(ArgSettings::TakesValue)); assert!(!a.is_set(ArgSettings::Required)); - assert_eq!(a.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(a.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(a.num_vals.is_none()); } @@ -416,8 +411,7 @@ mod test { assert!(a.is_set(ArgSettings::Multiple)); assert!(a.is_set(ArgSettings::TakesValue)); assert!(!a.is_set(ArgSettings::Required)); - assert_eq!(a.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(a.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(a.num_vals.is_none()); } @@ -431,8 +425,7 @@ mod test { assert!(b.is_set(ArgSettings::Multiple)); assert!(b.is_set(ArgSettings::TakesValue)); assert!(!b.is_set(ArgSettings::Required)); - assert_eq!(b.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(b.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(b.num_vals.is_none()); } @@ -446,8 +439,7 @@ mod test { assert!(c.is_set(ArgSettings::Multiple)); assert!(c.is_set(ArgSettings::TakesValue)); assert!(c.is_set(ArgSettings::Required)); - assert_eq!(c.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(c.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(c.num_vals.is_none()); } @@ -461,8 +453,7 @@ mod test { assert!(c.is_set(ArgSettings::Multiple)); assert!(c.is_set(ArgSettings::TakesValue)); assert!(c.is_set(ArgSettings::Required)); - assert_eq!(c.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(c.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(c.num_vals.is_none()); } @@ -476,8 +467,7 @@ mod test { assert!(d.is_set(ArgSettings::Multiple)); assert!(d.is_set(ArgSettings::TakesValue)); assert!(d.is_set(ArgSettings::Required)); - assert_eq!(d.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(d.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(d.num_vals.is_none()); } @@ -491,8 +481,7 @@ mod test { assert!(!a.is_set(ArgSettings::Multiple)); assert!(a.is_set(ArgSettings::TakesValue)); assert!(!a.is_set(ArgSettings::Required)); - assert_eq!(a.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(a.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(a.num_vals.is_none()); } @@ -506,8 +495,8 @@ mod test { assert!(!b.is_set(ArgSettings::Multiple)); assert!(b.is_set(ArgSettings::TakesValue)); assert!(!b.is_set(ArgSettings::Required)); - assert_eq!(b.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(b.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(b.num_vals.is_none()); } @@ -521,8 +510,7 @@ mod test { assert!(!c.is_set(ArgSettings::Multiple)); assert!(c.is_set(ArgSettings::TakesValue)); assert!(c.is_set(ArgSettings::Required)); - assert_eq!(c.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(c.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(c.num_vals.is_none()); } @@ -536,8 +524,8 @@ mod test { assert!(!d.is_set(ArgSettings::Multiple)); assert!(d.is_set(ArgSettings::TakesValue)); assert!(d.is_set(ArgSettings::Required)); - assert_eq!(d.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(d.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(d.num_vals.is_none()); } @@ -551,8 +539,7 @@ mod test { assert!(a.is_set(ArgSettings::Multiple)); assert!(a.is_set(ArgSettings::TakesValue)); assert!(!a.is_set(ArgSettings::Required)); - assert_eq!(a.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(a.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(a.num_vals.is_none()); } @@ -566,8 +553,7 @@ mod test { assert!(a.is_set(ArgSettings::Multiple)); assert!(a.is_set(ArgSettings::TakesValue)); assert!(!a.is_set(ArgSettings::Required)); - assert_eq!(a.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(a.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(a.num_vals.is_none()); } @@ -581,8 +567,8 @@ mod test { assert!(b.is_set(ArgSettings::Multiple)); assert!(b.is_set(ArgSettings::TakesValue)); assert!(!b.is_set(ArgSettings::Required)); - assert_eq!(b.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(b.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(b.num_vals.is_none()); } @@ -596,8 +582,7 @@ mod test { assert!(c.is_set(ArgSettings::Multiple)); assert!(c.is_set(ArgSettings::TakesValue)); assert!(c.is_set(ArgSettings::Required)); - assert_eq!(c.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(c.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(c.num_vals.is_none()); } @@ -611,8 +596,7 @@ mod test { assert!(c.is_set(ArgSettings::Multiple)); assert!(c.is_set(ArgSettings::TakesValue)); assert!(c.is_set(ArgSettings::Required)); - assert_eq!(c.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(c.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(c.num_vals.is_none()); } @@ -626,8 +610,8 @@ mod test { assert!(d.is_set(ArgSettings::Multiple)); assert!(d.is_set(ArgSettings::TakesValue)); assert!(d.is_set(ArgSettings::Required)); - assert_eq!(d.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(d.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(d.num_vals.is_none()); } @@ -641,8 +625,7 @@ mod test { assert!(!a.is_set(ArgSettings::Multiple)); assert!(a.is_set(ArgSettings::TakesValue)); assert!(!a.is_set(ArgSettings::Required)); - assert_eq!(a.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(a.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(a.num_vals.is_none()); } @@ -656,8 +639,8 @@ mod test { assert!(!b.is_set(ArgSettings::Multiple)); assert!(b.is_set(ArgSettings::TakesValue)); assert!(!b.is_set(ArgSettings::Required)); - assert_eq!(b.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(b.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(b.num_vals.is_none()); } @@ -671,8 +654,7 @@ mod test { assert!(!c.is_set(ArgSettings::Multiple)); assert!(c.is_set(ArgSettings::TakesValue)); assert!(c.is_set(ArgSettings::Required)); - assert_eq!(c.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(c.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(c.num_vals.is_none()); } @@ -686,8 +668,8 @@ mod test { assert!(!d.is_set(ArgSettings::Multiple)); assert!(d.is_set(ArgSettings::TakesValue)); assert!(d.is_set(ArgSettings::Required)); - assert_eq!(d.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(d.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(d.num_vals.is_none()); } @@ -701,8 +683,7 @@ mod test { assert!(a.is_set(ArgSettings::Multiple)); assert!(a.is_set(ArgSettings::TakesValue)); assert!(!a.is_set(ArgSettings::Required)); - assert_eq!(a.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(a.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(a.num_vals.is_none()); } @@ -716,8 +697,7 @@ mod test { assert!(a.is_set(ArgSettings::Multiple)); assert!(a.is_set(ArgSettings::TakesValue)); assert!(!a.is_set(ArgSettings::Required)); - assert_eq!(a.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(a.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(a.num_vals.is_none()); } @@ -731,8 +711,8 @@ mod test { assert!(b.is_set(ArgSettings::Multiple)); assert!(b.is_set(ArgSettings::TakesValue)); assert!(!b.is_set(ArgSettings::Required)); - assert_eq!(b.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(b.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(b.num_vals.is_none()); } @@ -746,8 +726,7 @@ mod test { assert!(c.is_set(ArgSettings::Multiple)); assert!(c.is_set(ArgSettings::TakesValue)); assert!(c.is_set(ArgSettings::Required)); - assert_eq!(c.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(c.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(c.num_vals.is_none()); } @@ -761,8 +740,7 @@ mod test { assert!(c.is_set(ArgSettings::Multiple)); assert!(c.is_set(ArgSettings::TakesValue)); assert!(c.is_set(ArgSettings::Required)); - assert_eq!(c.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(c.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(c.num_vals.is_none()); } @@ -776,8 +754,8 @@ mod test { assert!(d.is_set(ArgSettings::Multiple)); assert!(d.is_set(ArgSettings::TakesValue)); assert!(d.is_set(ArgSettings::Required)); - assert_eq!(d.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(d.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(d.num_vals.is_none()); } @@ -791,8 +769,8 @@ mod test { assert!(!a.is_set(ArgSettings::Multiple)); assert!(a.is_set(ArgSettings::TakesValue)); assert!(!a.is_set(ArgSettings::Required)); - assert_eq!(a.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(a.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(a.num_vals.is_none()); } @@ -806,8 +784,8 @@ mod test { assert!(!b.is_set(ArgSettings::Multiple)); assert!(b.is_set(ArgSettings::TakesValue)); assert!(!b.is_set(ArgSettings::Required)); - assert_eq!(b.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(b.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(b.num_vals.is_none()); } @@ -821,8 +799,7 @@ mod test { assert!(!c.is_set(ArgSettings::Multiple)); assert!(c.is_set(ArgSettings::TakesValue)); assert!(c.is_set(ArgSettings::Required)); - assert_eq!(c.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(c.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(c.num_vals.is_none()); } @@ -836,8 +813,8 @@ mod test { assert!(!d.is_set(ArgSettings::Multiple)); assert!(d.is_set(ArgSettings::TakesValue)); assert!(d.is_set(ArgSettings::Required)); - assert_eq!(d.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(d.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(d.num_vals.is_none()); } @@ -851,8 +828,8 @@ mod test { assert!(a.is_set(ArgSettings::Multiple)); assert!(a.is_set(ArgSettings::TakesValue)); assert!(!a.is_set(ArgSettings::Required)); - assert_eq!(a.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(a.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(a.num_vals.is_none()); } @@ -866,8 +843,8 @@ mod test { assert!(b.is_set(ArgSettings::Multiple)); assert!(b.is_set(ArgSettings::TakesValue)); assert!(!b.is_set(ArgSettings::Required)); - assert_eq!(b.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(b.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(b.num_vals.is_none()); } @@ -881,8 +858,7 @@ mod test { assert!(c.is_set(ArgSettings::Multiple)); assert!(c.is_set(ArgSettings::TakesValue)); assert!(c.is_set(ArgSettings::Required)); - assert_eq!(c.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(c.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(c.num_vals.is_none()); } @@ -896,8 +872,8 @@ mod test { assert!(d.is_set(ArgSettings::Multiple)); assert!(d.is_set(ArgSettings::TakesValue)); assert!(d.is_set(ArgSettings::Required)); - assert_eq!(d.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(d.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(d.num_vals.is_none()); } @@ -911,8 +887,8 @@ mod test { assert!(!a.is_set(ArgSettings::Multiple)); assert!(a.is_set(ArgSettings::TakesValue)); assert!(!a.is_set(ArgSettings::Required)); - assert_eq!(a.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(a.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(a.num_vals.is_none()); } @@ -926,8 +902,8 @@ mod test { assert!(!b.is_set(ArgSettings::Multiple)); assert!(b.is_set(ArgSettings::TakesValue)); assert!(!b.is_set(ArgSettings::Required)); - assert_eq!(b.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(b.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(b.num_vals.is_none()); } @@ -941,8 +917,7 @@ mod test { assert!(!c.is_set(ArgSettings::Multiple)); assert!(c.is_set(ArgSettings::TakesValue)); assert!(c.is_set(ArgSettings::Required)); - assert_eq!(c.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(c.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(c.num_vals.is_none()); } @@ -956,8 +931,8 @@ mod test { assert!(!d.is_set(ArgSettings::Multiple)); assert!(d.is_set(ArgSettings::TakesValue)); assert!(d.is_set(ArgSettings::Required)); - assert_eq!(d.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(d.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(d.num_vals.is_none()); } @@ -971,8 +946,8 @@ mod test { assert!(a.is_set(ArgSettings::Multiple)); assert!(a.is_set(ArgSettings::TakesValue)); assert!(!a.is_set(ArgSettings::Required)); - assert_eq!(a.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(a.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(a.num_vals.is_none()); } @@ -986,8 +961,8 @@ mod test { assert!(b.is_set(ArgSettings::Multiple)); assert!(b.is_set(ArgSettings::TakesValue)); assert!(!b.is_set(ArgSettings::Required)); - assert_eq!(b.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(b.val_names.unwrap().values().collect::>(), + [&"option"]); assert!(b.num_vals.is_none()); } @@ -1001,8 +976,7 @@ mod test { assert!(c.is_set(ArgSettings::Multiple)); assert!(c.is_set(ArgSettings::TakesValue)); assert!(c.is_set(ArgSettings::Required)); - assert_eq!(c.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["opt"]); + assert_eq!(c.val_names.unwrap().values().collect::>(), [&"opt"]); assert!(c.num_vals.is_none()); } @@ -1016,8 +990,7 @@ mod test { assert!(d.is_set(ArgSettings::Multiple)); assert!(d.is_set(ArgSettings::TakesValue)); assert!(d.is_set(ArgSettings::Required)); - assert_eq!(d.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["option"]); + assert_eq!(d.val_names.unwrap().values().collect::>(), [&"option"]); assert!(d.num_vals.is_none()); } @@ -1031,8 +1004,8 @@ mod test { assert!(!d.is_set(ArgSettings::Multiple)); assert!(d.is_set(ArgSettings::TakesValue)); assert!(d.is_set(ArgSettings::Required)); - assert_eq!(d.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["file", "mode"]); + assert_eq!(d.val_names.unwrap().values().collect::>(), + [&"file", &"mode"]); assert_eq!(d.num_vals.unwrap(), 2); } @@ -1046,8 +1019,8 @@ mod test { assert!(d.is_set(ArgSettings::Multiple)); assert!(d.is_set(ArgSettings::TakesValue)); assert!(d.is_set(ArgSettings::Required)); - assert_eq!(d.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["file", "mode"]); + assert_eq!(d.val_names.unwrap().values().collect::>(), + [&"file", &"mode"]); assert_eq!(d.num_vals.unwrap(), 2); } @@ -1061,8 +1034,8 @@ mod test { assert!(d.is_set(ArgSettings::Multiple)); assert!(d.is_set(ArgSettings::TakesValue)); assert!(d.is_set(ArgSettings::Required)); - assert_eq!(d.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["file", "mode"]); + assert_eq!(d.val_names.unwrap().values().collect::>(), + [&"file", &"mode"]); assert_eq!(d.num_vals.unwrap(), 2); } @@ -1076,8 +1049,8 @@ mod test { assert!(!d.is_set(ArgSettings::Multiple)); assert!(d.is_set(ArgSettings::TakesValue)); assert!(!d.is_set(ArgSettings::Required)); - assert_eq!(d.val_names.unwrap().iter().map(|(_, &v)| v).collect::>(), - ["file", "mode"]); + assert_eq!(d.val_names.unwrap().values().collect::>(), + [&"file", &"mode"]); assert_eq!(d.num_vals.unwrap(), 2); }