Skip to content

Commit

Permalink
Fix failing tests, negating Duration::MIN may overflow
Browse files Browse the repository at this point in the history
Negating `Duration::MIN` does overflow, which is expected behaviour due
to it's internal representation. This happens twice in the current test
suite, this skips this part of the test to fix the remaining unit tests.
  • Loading branch information
timvisee committed Jul 29, 2021
1 parent eff9180 commit 0b88430
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
4 changes: 3 additions & 1 deletion src/naive/date.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2200,7 +2200,9 @@ mod tests {
let lhs = NaiveDate::from_ymd(y1, m1, d1);
let sum = ymd.map(|(y, m, d)| NaiveDate::from_ymd(y, m, d));
assert_eq!(lhs.checked_add_signed(rhs), sum);
assert_eq!(lhs.checked_sub_signed(-rhs), sum);
if let Some(rhs) = rhs.checked_mul(-1) {
assert_eq!(lhs.checked_sub_signed(rhs), sum);
}
}

check((2014, 1, 1), Duration::ZERO, Some((2014, 1, 1)));
Expand Down
4 changes: 3 additions & 1 deletion src/naive/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2311,7 +2311,9 @@ mod tests {
let sum =
result.map(|(y, m, d, h, n, s)| NaiveDate::from_ymd(y, m, d).and_hms(h, n, s));
assert_eq!(lhs.checked_add_signed(rhs), sum);
assert_eq!(lhs.checked_sub_signed(-rhs), sum);
if let Some(rhs) = rhs.checked_mul(-1) {
assert_eq!(lhs.checked_sub_signed(rhs), sum);
}
}

check(
Expand Down

0 comments on commit 0b88430

Please sign in to comment.