Skip to content

Commit

Permalink
Avoid failing test
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpratt committed Dec 24, 2023
1 parent 4a74924 commit d7d9f6a
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 4 deletions.
1 change: 0 additions & 1 deletion tests/date.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
use core::i32;
use std::cmp::Ordering;
use std::collections::HashSet;

Expand Down
28 changes: 25 additions & 3 deletions tests/quickcheck.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use num_conv::prelude::*;
use quickcheck::{Arbitrary, TestResult};
use quickcheck_macros::quickcheck;
use time::macros::time;
use time::Weekday::*;
use time::{Date, Duration, Month, OffsetDateTime, PrimitiveDateTime, Time, UtcOffset, Weekday};

Expand Down Expand Up @@ -148,7 +150,7 @@ fn weekday_can_shrink(w: Weekday) -> bool {

#[quickcheck]
fn month_supports_arbitrary(m: Month) -> bool {
(1..=12).contains(&(m as u8))
(1..=12).contains(&u8::from(m))
}

#[quickcheck]
Expand Down Expand Up @@ -248,7 +250,17 @@ fn odt_sub_no_panic(left: OffsetDateTime, right: OffsetDateTime) -> bool {

#[quickcheck]
fn odt_to_offset_no_panic(odt: OffsetDateTime, offset: UtcOffset) -> TestResult {
if odt.date() == Date::MIN || odt.date() == Date::MAX {
if Date::MIN
.midnight()
.assume_utc()
.checked_add(Duration::seconds(offset.whole_seconds().extend()))
.is_none()
|| Date::MAX
.with_time(time!(23:59:59.999_999_999))
.assume_utc()
.checked_add(Duration::seconds(offset.whole_seconds().extend()))
.is_none()
{
return TestResult::discard();
}

Expand All @@ -259,7 +271,17 @@ fn odt_to_offset_no_panic(odt: OffsetDateTime, offset: UtcOffset) -> TestResult

#[quickcheck]
fn odt_replace_offset_no_panic(odt: OffsetDateTime, offset: UtcOffset) -> TestResult {
if odt.date() == Date::MIN || odt.date() == Date::MAX {
if Date::MIN
.midnight()
.assume_offset(odt.offset())
.checked_add(Duration::seconds(offset.whole_seconds().extend()))
.is_none()
|| Date::MAX
.with_time(time!(23:59:59.999_999_999))
.assume_offset(odt.offset())
.checked_add(Duration::seconds(offset.whole_seconds().extend()))
.is_none()
{
return TestResult::discard();
}

Expand Down
1 change: 1 addition & 0 deletions time/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ num_threads = { workspace = true, optional = true }
js-sys = { workspace = true, optional = true }

[dev-dependencies]
num-conv = { workspace = true }
rand = { workspace = true }
serde = { workspace = true, features = ["derive"] }
serde_json = { workspace = true }
Expand Down

0 comments on commit d7d9f6a

Please sign in to comment.