mirror of
https://github.com/sharkdp/hyperfine.git
synced 2026-10-31 00:40:18 +00:00
Reject negative parameter steps before expanding ranges
This commit is contained in:
1 parent
0f7ae35626
commit
31ae72b2b7
5 files changed
+54
-2
No files matched your search
@@ -47,6 +47,10 @@ impl<T: Numeric> RangeStep<T> {
|
||||
return Err(ParameterScanError::ZeroStep);
|
||||
}
|
||||
|
||||
if step < T::from(0) {
|
||||
return Err(ParameterScanError::NegativeStep);
|
||||
}
|
||||
|
||||
const MAX_PARAMETERS: usize = 100_000;
|
||||
match range_step_size_hint(start, end, step) {
|
||||
(_, Some(size)) if size <= MAX_PARAMETERS => Ok(Self {
|
||||
@@ -120,6 +124,36 @@ mod tests {
|
||||
assert_eq!(param_range[10], Decimal::from(1));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_negative_integer_step() {
|
||||
for step in [-2, -3, i32::MIN, -1] {
|
||||
for end in [0, 1, 10] {
|
||||
let result = RangeStep::new(0, end, step);
|
||||
assert_eq!(
|
||||
result.unwrap_err().to_string(),
|
||||
"Parameter step size must be positive"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_negative_decimal_step() {
|
||||
for step in ["-2.0", "-0.1"] {
|
||||
for end in [0, 1, 10] {
|
||||
let result = RangeStep::new(
|
||||
Decimal::ZERO,
|
||||
Decimal::from(end),
|
||||
Decimal::from_str(step).unwrap(),
|
||||
);
|
||||
assert_eq!(
|
||||
result.unwrap_err().to_string(),
|
||||
"Parameter step size must be positive"
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_range_step_validate() {
|
||||
let result = RangeStep::new(0, 10, 3);
|
||||
|
||||
Reference in new issue
Block a user