Skip to content

Commit e2083d5

Browse files
nekevssjedel1043
authored andcommitted
Add test for sanity
1 parent 98c9f2b commit e2083d5

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

src/builtins/core/instant.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,28 @@ mod tests {
360360
assert!(Instant::try_new(min_minus_one).is_err());
361361
}
362362

363+
#[test]
364+
fn max_min_epoch_millseconds() {
365+
// Assert the casting is valid.
366+
let max = NS_MAX_INSTANT;
367+
let min = NS_MIN_INSTANT;
368+
let max_instant = Instant::try_new(max).unwrap();
369+
let min_instant = Instant::try_new(min).unwrap();
370+
371+
// Assert max and min are valid for casting.
372+
assert_eq!(
373+
max_instant.epoch_milliseconds(),
374+
max.div_euclid(1_000_000) as i64
375+
);
376+
assert_eq!(
377+
min_instant.epoch_milliseconds(),
378+
min.div_euclid(1_000_000) as i64
379+
);
380+
// Assert the max and min are not being truncated.
381+
assert_ne!(max_instant.epoch_milliseconds(), i64::MAX);
382+
assert_ne!(max_instant.epoch_milliseconds(), i64::MIN);
383+
}
384+
363385
#[test]
364386
fn instant_parsing_limits() {
365387
// valid cases

0 commit comments

Comments
 (0)