From 7d2fce56a415e93f9f5483d9c0b93d5831a3cc2d Mon Sep 17 00:00:00 2001 From: Jonathan Strong Date: Mon, 31 Dec 2018 02:26:15 -0500 Subject: [PATCH] add test to verify Utc -> nanos is lossless --- src/lib.rs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/lib.rs b/src/lib.rs index 0478fef..54024b1 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -118,3 +118,21 @@ pub fn short_uuid(id: &Uuid) -> String { format!("{}", &id.to_string()[..8]) } } + +#[allow(unused)] +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn utc_nanos_round_trip() { + let utc = Utc::now(); + let ns = inanos(utc); + let rt = nanos_utc(ns); + assert_eq!(utc, rt); + let utc = Utc.ymd(1970, 1, 1).and_hms(0, 0, 0); + let ns = inanos(utc); + let rt = nanos_utc(ns); + assert_eq!(utc, rt); + } +}