Skip to content

Commit 22a0d40

Browse files
committed
Add test for the size of chrono's main data types
1 parent d9d6b63 commit 22a0d40

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

src/lib.rs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,3 +627,27 @@ macro_rules! expect {
627627
}
628628
};
629629
}
630+
631+
#[cfg(test)]
632+
mod tests {
633+
#[cfg(feature = "clock")]
634+
use crate::{DateTime, FixedOffset, Local, NaiveDate, NaiveDateTime, NaiveTime, Utc};
635+
636+
#[test]
637+
#[allow(deprecated)]
638+
#[cfg(feature = "clock")]
639+
fn test_type_sizes() {
640+
use core::mem::size_of;
641+
assert_eq!(size_of::<NaiveDate>(), 4);
642+
assert_eq!(size_of::<Option<NaiveDate>>(), 8);
643+
assert_eq!(size_of::<NaiveTime>(), 8);
644+
assert_eq!(size_of::<Option<NaiveTime>>(), 12);
645+
assert_eq!(size_of::<NaiveDateTime>(), 12);
646+
assert_eq!(size_of::<Option<NaiveDateTime>>(), 16);
647+
648+
assert_eq!(size_of::<DateTime<Utc>>(), 12);
649+
assert_eq!(size_of::<DateTime<FixedOffset>>(), 16);
650+
assert_eq!(size_of::<DateTime<Local>>(), 16);
651+
assert_eq!(size_of::<Option<DateTime<FixedOffset>>>(), 20);
652+
}
653+
}

0 commit comments

Comments
 (0)