From d2e96abe16cfc884379f925c97235fa0e1edde61 Mon Sep 17 00:00:00 2001 From: muzarski Date: Thu, 25 Apr 2024 16:18:06 +0200 Subject: [PATCH] cqlvalue: make conversion to time_03 test utils Since some other version of time_03 might be supported in the future, we cannot have multiple methods such as `as_date()` defined. I don't think it's good idea to expose version specific methods (e.g. `as_date_03()`) to the users. This is why we make them test utilities only. --- scylla-cql/src/frame/response/result.rs | 35 ++++++++++++++----------- 1 file changed, 19 insertions(+), 16 deletions(-) diff --git a/scylla-cql/src/frame/response/result.rs b/scylla-cql/src/frame/response/result.rs index e5815d9daa..29479cbefb 100644 --- a/scylla-cql/src/frame/response/result.rs +++ b/scylla-cql/src/frame/response/result.rs @@ -192,8 +192,9 @@ impl CqlValue { self.as_cql_date().and_then(|date| date.try_into().ok()) } + #[cfg(test)] #[cfg(feature = "time-03")] - pub fn as_date(&self) -> Option { + fn as_date_03(&self) -> Option { self.as_cql_date().and_then(|date| date.try_into().ok()) } @@ -209,8 +210,9 @@ impl CqlValue { self.as_cql_timestamp().and_then(|ts| ts.try_into().ok()) } + #[cfg(test)] #[cfg(feature = "time-03")] - pub fn as_offset_date_time(&self) -> Option { + fn as_offset_date_time_03(&self) -> Option { self.as_cql_timestamp().and_then(|ts| ts.try_into().ok()) } @@ -226,8 +228,9 @@ impl CqlValue { self.as_cql_time().and_then(|ts| ts.try_into().ok()) } + #[cfg(test)] #[cfg(feature = "time-03")] - pub fn as_time(&self) -> Option { + fn as_time_03(&self) -> Option { self.as_cql_time().and_then(|ts| ts.try_into().ok()) } @@ -1330,7 +1333,7 @@ mod tests { super::deser_cql_value(&ColumnType::Date, &mut (1u32 << 31).to_be_bytes().as_ref()) .unwrap(); - assert_eq!(date.as_date(), Some(unix_epoch)); + assert_eq!(date.as_date_03(), Some(unix_epoch)); // 2^31 - 30 when converted to time_03::Date is 1969-12-02 let before_epoch = Date::from_calendar_date(1969, December, 2).unwrap(); @@ -1340,7 +1343,7 @@ mod tests { ) .unwrap(); - assert_eq!(date.as_date(), Some(before_epoch)); + assert_eq!(date.as_date_03(), Some(before_epoch)); // 2^31 + 30 when converted to time_03::Date is 1970-01-31 let after_epoch = Date::from_calendar_date(1970, January, 31).unwrap(); @@ -1350,20 +1353,20 @@ mod tests { ) .unwrap(); - assert_eq!(date.as_date(), Some(after_epoch)); + assert_eq!(date.as_date_03(), Some(after_epoch)); // 0 and u32::MAX are out of NaiveDate range, fails with an error, not panics assert_eq!( super::deser_cql_value(&ColumnType::Date, &mut 0_u32.to_be_bytes().as_ref()) .unwrap() - .as_date(), + .as_date_03(), None ); assert_eq!( super::deser_cql_value(&ColumnType::Date, &mut u32::MAX.to_be_bytes().as_ref()) .unwrap() - .as_date(), + .as_date_03(), None ); } @@ -1442,7 +1445,7 @@ mod tests { super::deser_cql_value(&ColumnType::Time, &mut (0i64).to_be_bytes().as_ref()).unwrap(); dbg!(&time); - assert_eq!(time.as_time(), Some(midnight)); + assert_eq!(time.as_time_03(), Some(midnight)); // 10:10:30.500,000,001 let (h, m, s, n) = (10, 10, 30, 500_000_001); @@ -1455,7 +1458,7 @@ mod tests { ) .unwrap(); - assert_eq!(time.as_time(), Some(midnight)); + assert_eq!(time.as_time_03(), Some(midnight)); // 23:59:59.999,999,999 let (h, m, s, n) = (23, 59, 59, 999_999_999); @@ -1468,7 +1471,7 @@ mod tests { ) .unwrap(); - assert_eq!(time.as_time(), Some(midnight)); + assert_eq!(time.as_time_03(), Some(midnight)); } #[test] @@ -1552,7 +1555,7 @@ mod tests { let date = super::deser_cql_value(&ColumnType::Timestamp, &mut 0i64.to_be_bytes().as_ref()) .unwrap(); - assert_eq!(date.as_offset_date_time(), Some(unix_epoch)); + assert_eq!(date.as_offset_date_time_03(), Some(unix_epoch)); // When converted to NaiveDateTime, this is 1969-12-01 11:29:29.5 let timestamp: i64 = -((((30 * 24 + 12) * 60 + 30) * 60 + 30) * 1000 + 500); @@ -1567,7 +1570,7 @@ mod tests { ) .unwrap(); - assert_eq!(date.as_offset_date_time(), Some(before_epoch)); + assert_eq!(date.as_offset_date_time_03(), Some(before_epoch)); // when converted to NaiveDateTime, this is is 1970-01-31 12:30:30.5 let timestamp: i64 = (((30 * 24 + 12) * 60 + 30) * 60 + 30) * 1000 + 500; @@ -1582,20 +1585,20 @@ mod tests { ) .unwrap(); - assert_eq!(date.as_offset_date_time(), Some(after_epoch)); + assert_eq!(date.as_offset_date_time_03(), Some(after_epoch)); // 0 and u32::MAX are out of NaiveDate range, fails with an error, not panics assert_eq!( super::deser_cql_value(&ColumnType::Timestamp, &mut i64::MIN.to_be_bytes().as_ref()) .unwrap() - .as_offset_date_time(), + .as_offset_date_time_03(), None ); assert_eq!( super::deser_cql_value(&ColumnType::Timestamp, &mut i64::MAX.to_be_bytes().as_ref()) .unwrap() - .as_offset_date_time(), + .as_offset_date_time_03(), None ); }