From 9ebdf8cad5c8da83568ea097aac8a54ef7988f81 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 5 Dec 2024 15:32:24 +0100 Subject: [PATCH 1/2] test(lex): Allow 'E' in scientific notation --- clap_lex/tests/testsuite/parsed.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/clap_lex/tests/testsuite/parsed.rs b/clap_lex/tests/testsuite/parsed.rs index 4ee944cb4b5..6bc42ca2eb4 100644 --- a/clap_lex/tests/testsuite/parsed.rs +++ b/clap_lex/tests/testsuite/parsed.rs @@ -120,7 +120,7 @@ fn to_short() { #[test] fn is_negative_number() { - for number in ["-10.0", "-1", "-100", "-3.5", "-1e10", "-1.3e10"] { + for number in ["-10.0", "-1", "-100", "-3.5", "-1e10", "-1.3e10", "-1E10"] { let raw = clap_lex::RawArgs::new(["bin", number]); let mut cursor = raw.cursor(); assert_eq!(raw.next_os(&mut cursor), Some(OsStr::new("bin"))); @@ -142,7 +142,9 @@ fn is_positive_number() { #[test] fn is_not_number() { - for number in ["--10.0", "-..", "-2..", "-e", "-1e", "-1e10.2", "-.2"] { + for number in [ + "--10.0", "-..", "-2..", "-e", "-1e", "-1e10.2", "-.2", "-E", "-1E", "-1E10.2", + ] { let raw = clap_lex::RawArgs::new(["bin", number]); let mut cursor = raw.cursor(); assert_eq!(raw.next_os(&mut cursor), Some(OsStr::new("bin"))); From c8095c0b4d8b415cf7253b4c0a77c60485412e72 Mon Sep 17 00:00:00 2001 From: Daniel Hofstetter Date: Thu, 5 Dec 2024 15:34:35 +0100 Subject: [PATCH 2/2] fix(lex): Allow an exponent 'E' --- clap_lex/src/lib.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/clap_lex/src/lib.rs b/clap_lex/src/lib.rs index c0ba47e3c1d..4ff5871018e 100644 --- a/clap_lex/src/lib.rs +++ b/clap_lex/src/lib.rs @@ -505,9 +505,9 @@ fn is_number(arg: &str) -> bool { // optional exponent, and only if it's not the first character. b'.' if !seen_dot && position_of_e.is_none() && i > 0 => seen_dot = true, - // Allow an exponent `e` but only at most one after the first + // Allow an exponent `e`/`E` but only at most one after the first // character. - b'e' if position_of_e.is_none() && i > 0 => position_of_e = Some(i), + b'e' | b'E' if position_of_e.is_none() && i > 0 => position_of_e = Some(i), _ => return false, }