Skip to content

Commit

Permalink
Test init macros are const
Browse files Browse the repository at this point in the history
  • Loading branch information
pitdicker committed Sep 13, 2023
1 parent cec2280 commit b1769a6
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ macro_rules! offset {
#[cfg(test)]
#[rustfmt::skip::macros(date)]
mod tests {
use crate::{FixedOffset, NaiveDate, NaiveTime, TimeZone};
use crate::{DateTime, FixedOffset, NaiveDate, NaiveDateTime, NaiveTime, TimeZone};

#[test]
fn init_macros() {
Expand Down Expand Up @@ -273,4 +273,20 @@ mod tests {
assert_eq!(offset!(+05:43:21), FixedOffset::east_opt(20_601).unwrap());
assert_eq!(offset!(-05:43:21), FixedOffset::east_opt(-20_601).unwrap());
}

#[test]
fn macros_are_const() {
const DATE: NaiveDate = date!(2023-09-08);
const TIME: NaiveTime = time!(7:03:25);
const NAIVEDATETIME: NaiveDateTime = datetime!(2023-09-08 7:03:25);
assert_eq!(DATE.and_time(TIME), NAIVEDATETIME);

const OFFSET_1: FixedOffset = offset!(+02:00);
const DATETIME_1: DateTime<FixedOffset> = datetime!(2023-09-08 7:03:25+02:00);
assert_eq!(OFFSET_1.from_local_datetime(&NAIVEDATETIME).unwrap(), DATETIME_1);

const OFFSET_2: FixedOffset = offset!(+02:00);
const DATETIME_2: DateTime<FixedOffset> = datetime!(2023-09-08 7:03:25+02:00);
assert_eq!(OFFSET_2.from_local_datetime(&NAIVEDATETIME).unwrap(), DATETIME_2);
}
}

0 comments on commit b1769a6

Please sign in to comment.