From 25db147e874a9fde450c0215d8769e679d1cca18 Mon Sep 17 00:00:00 2001 From: Aaron Loucks Date: Fri, 28 Feb 2020 19:03:59 -0500 Subject: [PATCH] Port chrono tests to time tests --- tokio-postgres/Cargo.toml | 1 + tokio-postgres/tests/test/types/mod.rs | 2 + tokio-postgres/tests/test/types/time_02.rs | 147 +++++++++++++++++++++ 3 files changed, 150 insertions(+) create mode 100644 tokio-postgres/tests/test/types/time_02.rs diff --git a/tokio-postgres/Cargo.toml b/tokio-postgres/Cargo.toml index f3f8df73..f3bf3338 100644 --- a/tokio-postgres/Cargo.toml +++ b/tokio-postgres/Cargo.toml @@ -63,4 +63,5 @@ geo-types-04 = { version = "0.4", package = "geo-types" } serde-1 = { version = "1.0", package = "serde" } serde_json-1 = { version = "1.0", package = "serde_json" } uuid-08 = { version = "0.8", package = "uuid" } +time-02 = { version = "0.2", package = "time" } diff --git a/tokio-postgres/tests/test/types/mod.rs b/tokio-postgres/tests/test/types/mod.rs index df6a2e93..5d292db5 100644 --- a/tokio-postgres/tests/test/types/mod.rs +++ b/tokio-postgres/tests/test/types/mod.rs @@ -22,6 +22,8 @@ mod eui48_04; mod geo_010; #[cfg(feature = "with-serde_json-1")] mod serde_json_1; +#[cfg(feature = "with-time-0_2")] +mod time_02; #[cfg(feature = "with-uuid-0_8")] mod uuid_08; diff --git a/tokio-postgres/tests/test/types/time_02.rs b/tokio-postgres/tests/test/types/time_02.rs new file mode 100644 index 00000000..8690788b --- /dev/null +++ b/tokio-postgres/tests/test/types/time_02.rs @@ -0,0 +1,147 @@ +use time_02::{OffsetDateTime, PrimitiveDateTime}; +use tokio_postgres::types::{Date, Timestamp}; + +use crate::types::test_type; + +#[tokio::test] +async fn test_naive_date_time_params() { + fn make_check(time: &str) -> (Option, &str) { + ( + Some(PrimitiveDateTime::parse(time, "'%Y-%m-%d %H:%M:%S.%f'").unwrap()), + time, + ) + } + test_type( + "TIMESTAMP", + &[ + make_check("'1970-01-01 00:00:00.010000000'"), + make_check("'1965-09-25 11:19:33.100314000'"), + make_check("'2010-02-09 23:11:45.120200000'"), + (None, "NULL"), + ], + ) + .await; +} + +#[tokio::test] +async fn test_with_special_naive_date_time_params() { + fn make_check(time: &str) -> (Timestamp, &str) { + ( + Timestamp::Value(PrimitiveDateTime::parse(time, "'%Y-%m-%d %H:%M:%S.%f'").unwrap()), + time, + ) + } + test_type( + "TIMESTAMP", + &[ + make_check("'1970-01-01 00:00:00.010000000'"), + make_check("'1965-09-25 11:19:33.100314000'"), + make_check("'2010-02-09 23:11:45.120200000'"), + (Timestamp::PosInfinity, "'infinity'"), + (Timestamp::NegInfinity, "'-infinity'"), + ], + ) + .await; +} + +#[tokio::test] +async fn test_date_time_params() { + fn make_check(time: &str) -> (Option, &str) { + ( + Some(OffsetDateTime::parse(time, "'%Y-%m-%d %H:%M:%S.%f'").unwrap()), + time, + ) + } + test_type( + "TIMESTAMP WITH TIME ZONE", + &[ + make_check("'1970-01-01 00:00:00.010000000'"), + make_check("'1965-09-25 11:19:33.100314000'"), + make_check("'2010-02-09 23:11:45.120200000'"), + (None, "NULL"), + ], + ) + .await; +} + +#[tokio::test] +async fn test_with_special_date_time_params() { + fn make_check(time: &str) -> (Timestamp, &str) { + ( + Timestamp::Value(OffsetDateTime::parse(time, "'%Y-%m-%d %H:%M:%S.%f'").unwrap()), + time, + ) + } + test_type( + "TIMESTAMP WITH TIME ZONE", + &[ + make_check("'1970-01-01 00:00:00.010000000'"), + make_check("'1965-09-25 11:19:33.100314000'"), + make_check("'2010-02-09 23:11:45.120200000'"), + (Timestamp::PosInfinity, "'infinity'"), + (Timestamp::NegInfinity, "'-infinity'"), + ], + ) + .await; +} + +#[tokio::test] +async fn test_date_params() { + fn make_check(time: &str) -> (Option, &str) { + ( + Some(time_02::Date::parse(time, "'%Y-%m-%d'").unwrap()), + time, + ) + } + test_type( + "DATE", + &[ + make_check("'1970-01-01'"), + make_check("'1965-09-25'"), + make_check("'2010-02-09'"), + (None, "NULL"), + ], + ) + .await; +} + +#[tokio::test] +async fn test_with_special_date_params() { + fn make_check(date: &str) -> (Date, &str) { + ( + Date::Value(time_02::Date::parse(date, "'%Y-%m-%d'").unwrap()), + date, + ) + } + test_type( + "DATE", + &[ + make_check("'1970-01-01'"), + make_check("'1965-09-25'"), + make_check("'2010-02-09'"), + (Date::PosInfinity, "'infinity'"), + (Date::NegInfinity, "'-infinity'"), + ], + ) + .await; +} + +#[tokio::test] +async fn test_time_params() { + fn make_check(time: &str) -> (Option, &str) { + ( + Some(time_02::Time::parse(time, "'%H:%M:%S.%f'").unwrap()), + time, + ) + } + test_type( + "TIME", + &[ + make_check("'00:00:00.010000000'"), + make_check("'11:19:33.100314000'"), + make_check("'23:11:45.120200000'"), + (None, "NULL"), + ], + ) + .await; +}