mirror of
https://github.com/Orange-OpenSource/hurl.git
synced 2024-11-23 00:44:55 +03:00
Add minute unit for duration
This commit is contained in:
parent
730b4f6f98
commit
20c1f4bf74
@ -84,7 +84,7 @@ Short description:
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="client-key-option">client-key-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">key</span> <span class="grammar-literal">:</span> <a href="#value-string">value-string</a> <a href="#lt">lt</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="compressed-option">compressed-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">compressed</span> <span class="grammar-literal">:</span> <a href="#boolean-option">boolean-option</a> <a href="#lt">lt</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="connect-to-option">connect-to-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">connect-to</span> <span class="grammar-literal">:</span> <a href="#value-string">value-string</a> <a href="#lt">lt</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="delay-option">delay-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">delay</span> <span class="grammar-literal">:</span> <a href="#integer-option">integer-option</a> <a href="#lt">lt</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="delay-option">delay-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">delay</span> <span class="grammar-literal">:</span> <a href="#duration-option">duration-option</a> <a href="#lt">lt</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="follow-redirect-option">follow-redirect-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">location</span> <span class="grammar-literal">:</span> <a href="#boolean-option">boolean-option</a> <a href="#lt">lt</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="follow-redirect-trusted-option">follow-redirect-trusted-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">location-trusted</span> <span class="grammar-literal">:</span> <a href="#boolean-option">boolean-option</a> <a href="#lt">lt</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="http10-option">http10-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">http1.0</span> <span class="grammar-literal">:</span> <a href="#boolean-option">boolean-option</a> <a href="#lt">lt</a></div></div>
|
||||
@ -104,7 +104,7 @@ Short description:
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="resolve-option">resolve-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">resolve</span> <span class="grammar-literal">:</span> <a href="#value-string">value-string</a> <a href="#lt">lt</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="repeat-option">repeat-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">repeat</span> <span class="grammar-literal">:</span> <a href="#integer-option">integer-option</a> <a href="#lt">lt</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="retry-option">retry-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">retry</span> <span class="grammar-literal">:</span> <a href="#integer-option">integer-option</a> <a href="#lt">lt</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="retry-interval-option">retry-interval-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">retry-interval</span> <span class="grammar-literal">:</span> <a href="#integer-option">integer-option</a> <a href="#lt">lt</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="retry-interval-option">retry-interval-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">retry-interval</span> <span class="grammar-literal">:</span> <a href="#duration-option">duration-option</a> <a href="#lt">lt</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="skip-option">skip-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">skip</span> <span class="grammar-literal">:</span> <a href="#boolean-option">boolean-option</a> <a href="#lt">lt</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="unix-socket-option">unix-socket-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">unix-socket</span> <span class="grammar-literal">:</span> <a href="#value-string">value-string</a> <a href="#lt">lt</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="user-option">user-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">user</span> <span class="grammar-literal">:</span> <a href="#value-string">value-string</a> <a href="#lt">lt</a></div></div>
|
||||
@ -113,7 +113,9 @@ Short description:
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="very-verbose-option">very-verbose-option</span><span class="grammar-usedby">(used by <a href="#option">option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">very-verbose</span> <span class="grammar-literal">:</span> <a href="#boolean-option">boolean-option</a> <a href="#lt">lt</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="variable-definition">variable-definition</span><span class="grammar-usedby">(used by <a href="#variable-option">variable-option</a>)</span></div><div class="grammar-rule-expression"><a href="#variable-name">variable-name</a> <span class="grammar-literal">=</span> <a href="#variable-value">variable-value</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="boolean-option">boolean-option</span><span class="grammar-usedby">(used by <a href="#compressed-option">compressed-option</a>, <a href="#follow-redirect-option">follow-redirect-option</a>, <a href="#follow-redirect-trusted-option">follow-redirect-trusted-option</a>, <a href="#http10-option">http10-option</a>, <a href="#http11-option">http11-option</a>, <a href="#http2-option">http2-option</a>, <a href="#http3-option">http3-option</a>, <a href="#insecure-option">insecure-option</a>, <a href="#ipv4-option">ipv4-option</a>, <a href="#ipv6-option">ipv6-option</a>, <a href="#netrc-option">netrc-option</a>, <a href="#netrc-optional-option">netrc-optional-option</a>, <a href="#path-as-is-option">path-as-is-option</a>, <a href="#skip-option">skip-option</a>, <a href="#verbose-option">verbose-option</a>, <a href="#very-verbose-option">very-verbose-option</a>)</span></div><div class="grammar-rule-expression"><a href="#boolean">boolean</a><span class="grammar-symbol">|</span><a href="#template">template</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="integer-option">integer-option</span><span class="grammar-usedby">(used by <a href="#delay-option">delay-option</a>, <a href="#max-redirs-option">max-redirs-option</a>, <a href="#repeat-option">repeat-option</a>, <a href="#retry-option">retry-option</a>, <a href="#retry-interval-option">retry-interval-option</a>)</span></div><div class="grammar-rule-expression"><a href="#integer">integer</a><span class="grammar-symbol">|</span><a href="#template">template</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="integer-option">integer-option</span><span class="grammar-usedby">(used by <a href="#max-redirs-option">max-redirs-option</a>, <a href="#repeat-option">repeat-option</a>, <a href="#retry-option">retry-option</a>)</span></div><div class="grammar-rule-expression"><a href="#integer">integer</a><span class="grammar-symbol">|</span><a href="#template">template</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="duration-option">duration-option</span><span class="grammar-usedby">(used by <a href="#delay-option">delay-option</a>, <a href="#retry-interval-option">retry-interval-option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-symbol">(</span><a href="#integer">integer</a> <a href="#duration-unit">duration-unit</a><span class="grammar-symbol">?</span><span class="grammar-symbol">)</span><span class="grammar-symbol">|</span><a href="#template">template</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="duration-unit">duration-unit</span><span class="grammar-usedby">(used by <a href="#duration-option">duration-option</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">ms</span><span class="grammar-symbol">|</span><span class="grammar-literal">s</span><span class="grammar-symbol">|</span><span class="grammar-literal">m</span></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="variable-value">variable-value</span><span class="grammar-usedby">(used by <a href="#variable-definition">variable-definition</a>)</span></div><div class="grammar-rule-expression"> <a href="#null">null</a><br>
|
||||
<span class="grammar-symbol">|</span><a href="#boolean">boolean</a><br>
|
||||
<span class="grammar-symbol">|</span><a href="#integer">integer</a><br>
|
||||
@ -234,7 +236,7 @@ Short description:
|
||||
<span class="grammar-symbol">|</span><span class="grammar-literal">xml</span><br>
|
||||
<span class="grammar-symbol">|</span><span class="grammar-literal">graphql</span></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="multiline-string-attribute">multiline-string-attribute</span><span class="grammar-usedby">(used by <a href="#multiline-string">multiline-string</a>)</span></div><div class="grammar-rule-expression"> <span class="grammar-literal">escape</span><br>
|
||||
<span class="grammar-symbol">|</span><span class="grammar-literal">variable</span></div></div>
|
||||
<span class="grammar-symbol">|</span><span class="grammar-literal">novariable</span></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="multiline-string-content">multiline-string-content</span><span class="grammar-usedby">(used by <a href="#multiline-string">multiline-string</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-symbol">(</span><a href="#multiline-string-text">multiline-string-text</a><span class="grammar-symbol">|</span><a href="#multiline-string-escaped-char">multiline-string-escaped-char</a><span class="grammar-symbol">)</span><span class="grammar-symbol">*</span></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="multiline-string-text">multiline-string-text</span><span class="grammar-usedby">(used by <a href="#multiline-string-content">multiline-string-content</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-regex">~[\\]+</span> <span class="grammar-symbol">~</span><span class="grammar-literal">```</span></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="multiline-string-escaped-char">multiline-string-escaped-char</span><span class="grammar-usedby">(used by <a href="#multiline-string-content">multiline-string-content</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">\</span> <span class="grammar-symbol">(</span><span class="grammar-literal">\</span><span class="grammar-symbol">|</span><span class="grammar-literal">b</span><span class="grammar-symbol">|</span><span class="grammar-literal">f</span><span class="grammar-symbol">|</span><span class="grammar-literal">n</span><span class="grammar-symbol">|</span><span class="grammar-literal">r</span><span class="grammar-symbol">|</span><span class="grammar-literal">t</span><span class="grammar-symbol">|</span><span class="grammar-literal">`</span><span class="grammar-symbol">|</span><span class="grammar-literal">u</span> <a href="#unicode-char">unicode-char</a><span class="grammar-symbol">)</span></div></div>
|
||||
@ -262,7 +264,7 @@ Short description:
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="json-string-text">json-string-text</span><span class="grammar-usedby">(used by <a href="#json-string-content">json-string-content</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-regex">~["\\]</span></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="json-string-escaped-char">json-string-escaped-char</span><span class="grammar-usedby">(used by <a href="#json-string-content">json-string-content</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">\</span> <span class="grammar-symbol">(</span><span class="grammar-literal">"</span><span class="grammar-symbol">|</span><span class="grammar-literal">\</span><span class="grammar-symbol">|</span><span class="grammar-literal">b</span><span class="grammar-symbol">|</span><span class="grammar-literal">f</span><span class="grammar-symbol">|</span><span class="grammar-literal">n</span><span class="grammar-symbol">|</span><span class="grammar-literal">r</span><span class="grammar-symbol">|</span><span class="grammar-literal">t</span><span class="grammar-symbol">|</span><span class="grammar-literal">u</span> <a href="#hexdigit">hexdigit</a> <a href="#hexdigit">hexdigit</a> <a href="#hexdigit">hexdigit</a> <a href="#hexdigit">hexdigit</a><span class="grammar-symbol">)</span></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="json-number">json-number</span><span class="grammar-usedby">(used by <a href="#json-value">json-value</a>)</span></div><div class="grammar-rule-expression"><a href="#integer">integer</a> <a href="#fraction">fraction</a><span class="grammar-symbol">?</span> <a href="#exponent">exponent</a><span class="grammar-symbol">?</span></div></div>
|
||||
</div><div class="grammar-ruleset"><h3 id="template-expression">Template / Expression</h3><div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="template">template</span><span class="grammar-usedby">(used by <a href="#boolean-option">boolean-option</a>, <a href="#integer-option">integer-option</a>, <a href="#predicate-value">predicate-value</a>, <a href="#quoted-string">quoted-string</a>, <a href="#key-string">key-string</a>, <a href="#value-string">value-string</a>, <a href="#oneline-string">oneline-string</a>, <a href="#multiline-string">multiline-string</a>, <a href="#filename">filename</a>, <a href="#filename-password">filename-password</a>, <a href="#json-value">json-value</a>, <a href="#json-string">json-string</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">{{</span> <a href="#expr">expr</a> <span class="grammar-literal">}}</span></div></div>
|
||||
</div><div class="grammar-ruleset"><h3 id="template-expression">Template / Expression</h3><div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="template">template</span><span class="grammar-usedby">(used by <a href="#boolean-option">boolean-option</a>, <a href="#integer-option">integer-option</a>, <a href="#duration-option">duration-option</a>, <a href="#predicate-value">predicate-value</a>, <a href="#quoted-string">quoted-string</a>, <a href="#key-string">key-string</a>, <a href="#value-string">value-string</a>, <a href="#oneline-string">oneline-string</a>, <a href="#multiline-string">multiline-string</a>, <a href="#filename">filename</a>, <a href="#filename-password">filename-password</a>, <a href="#json-value">json-value</a>, <a href="#json-string">json-string</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">{{</span> <a href="#expr">expr</a> <span class="grammar-literal">}}</span></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="expr">expr</span><span class="grammar-usedby">(used by <a href="#template">template</a>)</span></div><div class="grammar-rule-expression"><a href="#variable-name">variable-name</a> <span class="grammar-symbol">(</span><a href="#sp">sp</a> <a href="#filter">filter</a><span class="grammar-symbol">)</span><span class="grammar-symbol">*</span></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="variable-name">variable-name</span><span class="grammar-usedby">(used by <a href="#variable-definition">variable-definition</a>, <a href="#expr">expr</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-regex">[A-Za-z]</span> <span class="grammar-regex">[A-Za-z_-0-9]*</span></div></div>
|
||||
</div><div class="grammar-ruleset"><h3 id="filter">Filter</h3><div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="filter">filter</span><span class="grammar-usedby">(used by <a href="#capture">capture</a>, <a href="#assert">assert</a>, <a href="#expr">expr</a>)</span></div><div class="grammar-rule-expression"> <a href="#count-filter">count-filter</a><br>
|
||||
@ -304,7 +306,7 @@ Short description:
|
||||
</div><div class="grammar-ruleset"><h3 id="lexical-grammar">Lexical Grammar</h3><div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="boolean">boolean</span><span class="grammar-usedby">(used by <a href="#boolean-option">boolean-option</a>, <a href="#variable-value">variable-value</a>, <a href="#predicate-value">predicate-value</a>, <a href="#json-value">json-value</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">true</span><span class="grammar-symbol">|</span><span class="grammar-literal">false</span></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="null">null</span><span class="grammar-usedby">(used by <a href="#variable-value">variable-value</a>, <a href="#predicate-value">predicate-value</a>, <a href="#json-value">json-value</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-literal">null</span></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="alphanum">alphanum</span><span class="grammar-usedby">(used by <a href="#key-string-text">key-string-text</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-regex">[A-Za-z0-9]</span></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="integer">integer</span><span class="grammar-usedby">(used by <a href="#integer-option">integer-option</a>, <a href="#variable-value">variable-value</a>, <a href="#json-number">json-number</a>, <a href="#nth-filter">nth-filter</a>, <a href="#float">float</a>, <a href="#number">number</a>)</span></div><div class="grammar-rule-expression"><a href="#digit">digit</a><span class="grammar-symbol">+</span></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="integer">integer</span><span class="grammar-usedby">(used by <a href="#integer-option">integer-option</a>, <a href="#duration-option">duration-option</a>, <a href="#variable-value">variable-value</a>, <a href="#json-number">json-number</a>, <a href="#nth-filter">nth-filter</a>, <a href="#float">float</a>, <a href="#number">number</a>)</span></div><div class="grammar-rule-expression"><a href="#digit">digit</a><span class="grammar-symbol">+</span></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="float">float</span><span class="grammar-usedby">(used by <a href="#variable-value">variable-value</a>, <a href="#number">number</a>)</span></div><div class="grammar-rule-expression"><a href="#integer">integer</a> <a href="#fraction">fraction</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="number">number</span><span class="grammar-usedby">(used by <a href="#greater-predicate">greater-predicate</a>, <a href="#greater-or-equal-predicate">greater-or-equal-predicate</a>, <a href="#less-predicate">less-predicate</a>, <a href="#less-or-equal-predicate">less-or-equal-predicate</a>, <a href="#predicate-value">predicate-value</a>)</span></div><div class="grammar-rule-expression"><a href="#integer">integer</a><span class="grammar-symbol">|</span><a href="#float">float</a></div></div>
|
||||
<div class="grammar-rule"><div class="grammar-rule-declaration"><span class="grammar-rule-id" id="digit">digit</span><span class="grammar-usedby">(used by <a href="#integer">integer</a>, <a href="#fraction">fraction</a>, <a href="#exponent">exponent</a>)</span></div><div class="grammar-rule-expression"><span class="grammar-regex">[0-9]</span></div></div>
|
||||
|
@ -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
|
||||
|
@ -80,5 +80,12 @@ mod tests {
|
||||
unit: Some(DurationUnit::MilliSecond)
|
||||
}
|
||||
);
|
||||
assert_eq!(
|
||||
parse("5m").unwrap(),
|
||||
Duration {
|
||||
value: 5,
|
||||
unit: Some(DurationUnit::Minute)
|
||||
}
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -552,6 +552,7 @@ fn get_duration(s: &str, default_unit: DurationUnit) -> Result<Duration, CliOpti
|
||||
let millis = match unit {
|
||||
DurationUnit::MilliSecond => duration.value,
|
||||
DurationUnit::Second => duration.value * 1000,
|
||||
DurationUnit::Minute => duration.value * 1000 * 60,
|
||||
};
|
||||
Ok(Duration::from_millis(millis))
|
||||
}
|
||||
|
@ -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,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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]
|
||||
|
@ -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<Self, Self::Err> {
|
||||
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}")),
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user