From 20c1f4bf74fb0c53515072a9172fc2c0ceca864f Mon Sep 17 00:00:00 2001 From: Fabrice Reix Date: Tue, 27 Aug 2024 13:31:47 +0200 Subject: [PATCH] Add minute unit for duration --- docs/grammar.md | 14 ++++++++------ docs/spec/grammar/hurl.grammar | 2 +- packages/hurl/src/cli/options/duration.rs | 7 +++++++ packages/hurl/src/cli/options/matches.rs | 1 + packages/hurl/src/runner/options.rs | 2 ++ packages/hurl_core/src/parser/duration.rs | 5 +++++ packages/hurl_core/src/typing.rs | 5 ++++- 7 files changed, 28 insertions(+), 8 deletions(-) diff --git a/docs/grammar.md b/docs/grammar.md index 575173784..84734f9a5 100644 --- a/docs/grammar.md +++ b/docs/grammar.md @@ -84,7 +84,7 @@ Short description:
client-key-option(used by option)
key : value-string lt
compressed-option(used by option)
compressed : boolean-option lt
connect-to-option(used by option)
connect-to : value-string lt
-
delay-option(used by option)
delay : integer-option lt
+
delay-option(used by option)
delay : duration-option lt
follow-redirect-option(used by option)
location : boolean-option lt
follow-redirect-trusted-option(used by option)
location-trusted : boolean-option lt
http10-option(used by option)
http1.0 : boolean-option lt
@@ -104,7 +104,7 @@ Short description:
resolve-option(used by option)
resolve : value-string lt
repeat-option(used by option)
repeat : integer-option lt
retry-option(used by option)
retry : integer-option lt
-
retry-interval-option(used by option)
retry-interval : integer-option lt
+
retry-interval-option(used by option)
retry-interval : duration-option lt
skip-option(used by option)
skip : boolean-option lt
unix-socket-option(used by option)
unix-socket : value-string lt
user-option(used by option)
user : value-string lt
@@ -113,7 +113,9 @@ Short description:
very-verbose-option(used by option)
very-verbose : boolean-option lt
variable-definition(used by variable-option)
-
+
integer-option(used by max-redirs-optionrepeat-optionretry-option)
+
duration-option(used by delay-optionretry-interval-option)
+
duration-unit(used by duration-option)
ms|s|m
variable-value(used by variable-definition)
 null
|boolean
|integer
@@ -234,7 +236,7 @@ Short description: |xml
|graphql
multiline-string-attribute(used by multiline-string)
 escape
-|variable
+|novariable
multiline-string-content(used by multiline-string)
multiline-string-text(used by multiline-string-content)
~[\\]+ ~```
multiline-string-escaped-char(used by multiline-string-content)
\ (\|b|f|n|r|t|`|u unicode-char)
@@ -262,7 +264,7 @@ Short description:
json-string-text(used by json-string-content)
~["\\]
json-string-escaped-char(used by json-string-content)
\ ("|\|b|f|n|r|t|u hexdigit hexdigit hexdigit hexdigit)
json-number(used by json-value)
-

Template / Expression

+

Template / Expression

expr(used by template)
variable-name(used by variable-definitionexpr)
[A-Za-z] [A-Za-z_-0-9]*

Filter

filter(used by captureassertexpr)
 count-filter
@@ -304,7 +306,7 @@ Short description:

Lexical Grammar

true|false
alphanum(used by key-string-text)
[A-Za-z0-9]
- +
digit(used by integerfractionexponent)
[0-9]
diff --git a/docs/spec/grammar/hurl.grammar b/docs/spec/grammar/hurl.grammar index 34b4f3633..38717d811 100644 --- a/docs/spec/grammar/hurl.grammar +++ b/docs/spec/grammar/hurl.grammar @@ -225,7 +225,7 @@ integer-option: integer | template duration-option: (integer duration-unit?) | template -duration-unit: "ms" | "s" +duration-unit: "ms" | "s" | "m" variable-value: null diff --git a/packages/hurl/src/cli/options/duration.rs b/packages/hurl/src/cli/options/duration.rs index eeedb52b7..8d61e285d 100644 --- a/packages/hurl/src/cli/options/duration.rs +++ b/packages/hurl/src/cli/options/duration.rs @@ -80,5 +80,12 @@ mod tests { unit: Some(DurationUnit::MilliSecond) } ); + assert_eq!( + parse("5m").unwrap(), + Duration { + value: 5, + unit: Some(DurationUnit::Minute) + } + ); } } diff --git a/packages/hurl/src/cli/options/matches.rs b/packages/hurl/src/cli/options/matches.rs index 65a862a77..698976de3 100644 --- a/packages/hurl/src/cli/options/matches.rs +++ b/packages/hurl/src/cli/options/matches.rs @@ -552,6 +552,7 @@ fn get_duration(s: &str, default_unit: DurationUnit) -> Result duration.value, DurationUnit::Second => duration.value * 1000, + DurationUnit::Minute => duration.value * 1000 * 60, }; Ok(Duration::from_millis(millis)) } diff --git a/packages/hurl/src/runner/options.rs b/packages/hurl/src/runner/options.rs index 417d51af4..fa0cb643b 100644 --- a/packages/hurl/src/runner/options.rs +++ b/packages/hurl/src/runner/options.rs @@ -367,6 +367,7 @@ fn eval_duration_option( match unit { DurationUnit::MilliSecond => value.value, DurationUnit::Second => value.value * 1000, + DurationUnit::Minute => value.value * 1000 * 60, } } DurationOption::Expression(expr) => match eval_expression(expr, variables)? { @@ -382,6 +383,7 @@ fn eval_duration_option( match default_unit { DurationUnit::MilliSecond => value as u64, DurationUnit::Second => (value * 1000) as u64, + DurationUnit::Minute => (value * 1000 * 60) as u64, } } } diff --git a/packages/hurl_core/src/parser/duration.rs b/packages/hurl_core/src/parser/duration.rs index 9ff68feb4..04f76138b 100644 --- a/packages/hurl_core/src/parser/duration.rs +++ b/packages/hurl_core/src/parser/duration.rs @@ -69,6 +69,11 @@ mod tests { duration_unit(&mut reader).unwrap().unwrap(), DurationUnit::MilliSecond ); + let mut reader = Reader::new("m\n"); + assert_eq!( + duration_unit(&mut reader).unwrap().unwrap(), + DurationUnit::Minute + ); } #[test] diff --git a/packages/hurl_core/src/typing.rs b/packages/hurl_core/src/typing.rs index 19759e3d9..5c5b636fc 100644 --- a/packages/hurl_core/src/typing.rs +++ b/packages/hurl_core/src/typing.rs @@ -44,6 +44,7 @@ impl Duration { pub enum DurationUnit { MilliSecond, Second, + Minute, } impl fmt::Display for Count { @@ -75,6 +76,7 @@ impl fmt::Display for DurationUnit { match self { DurationUnit::MilliSecond => write!(f, "ms"), DurationUnit::Second => write!(f, "s"), + DurationUnit::Minute => write!(f, "m"), } } } @@ -84,8 +86,9 @@ impl FromStr for DurationUnit { fn from_str(s: &str) -> Result { match s { - "s" => Ok(DurationUnit::Second), "ms" => Ok(DurationUnit::MilliSecond), + "s" => Ok(DurationUnit::Second), + "m" => Ok(DurationUnit::Minute), x => Err(format!("Invalid duration unit {x}")), } }