Skip to content

Commit 9b8f4f3

Browse files
committed
value: remove compatibility tests
As `deser_cql_value` was made use the new deserialization framework, these tests no longer test anything. Therefore, they are deleted. Their presence in the previous commits is useful, though, to prove that compatibility. It is worth noting that now, with `deser_cql_value` using the new framework, tests there in frame/response/result.rs now are used to test the deserialization implementation in the new framework.
1 parent ff37535 commit 9b8f4f3

File tree

1 file changed

+0
-313
lines changed
  • scylla-cql/src/types/deserialize

1 file changed

+0
-313
lines changed

scylla-cql/src/types/deserialize/value.rs

-313
Original file line numberDiff line numberDiff line change
@@ -1772,9 +1772,7 @@ pub(super) mod tests {
17721772
use std::fmt::Debug;
17731773
use std::net::{IpAddr, Ipv6Addr};
17741774

1775-
use crate::frame::response::cql_to_rust::FromCqlVal;
17761775
use crate::frame::response::result::{deser_cql_value, ColumnType, CqlValue};
1777-
use crate::frame::types;
17781776
use crate::frame::value::{
17791777
Counter, CqlDate, CqlDecimal, CqlDuration, CqlTime, CqlTimestamp, CqlTimeuuid, CqlVarint,
17801778
};
@@ -1907,286 +1905,6 @@ pub(super) mod tests {
19071905
assert_eq!(decoded_int, Some(MaybeEmpty::Empty));
19081906
}
19091907

1910-
#[test]
1911-
fn test_from_cql_value_compatibility() {
1912-
// This test should have a sub-case for each type
1913-
// that implements FromCqlValue
1914-
1915-
// fixed size integers
1916-
for i in 0..7 {
1917-
let v: i8 = 1 << i;
1918-
compat_check::<i8>(&ColumnType::TinyInt, make_bytes(&v.to_be_bytes()));
1919-
compat_check::<i8>(&ColumnType::TinyInt, make_bytes(&(-v).to_be_bytes()));
1920-
}
1921-
for i in 0..15 {
1922-
let v: i16 = 1 << i;
1923-
compat_check::<i16>(&ColumnType::SmallInt, make_bytes(&v.to_be_bytes()));
1924-
compat_check::<i16>(&ColumnType::SmallInt, make_bytes(&(-v).to_be_bytes()));
1925-
}
1926-
for i in 0..31 {
1927-
let v: i32 = 1 << i;
1928-
compat_check::<i32>(&ColumnType::Int, make_bytes(&v.to_be_bytes()));
1929-
compat_check::<i32>(&ColumnType::Int, make_bytes(&(-v).to_be_bytes()));
1930-
}
1931-
for i in 0..63 {
1932-
let v: i64 = 1 << i;
1933-
compat_check::<i64>(&ColumnType::BigInt, make_bytes(&v.to_be_bytes()));
1934-
compat_check::<i64>(&ColumnType::BigInt, make_bytes(&(-v).to_be_bytes()));
1935-
}
1936-
1937-
// bool
1938-
compat_check::<bool>(&ColumnType::Boolean, make_bytes(&[0]));
1939-
compat_check::<bool>(&ColumnType::Boolean, make_bytes(&[1]));
1940-
1941-
// fixed size floating point types
1942-
compat_check::<f32>(&ColumnType::Float, make_bytes(&123f32.to_be_bytes()));
1943-
compat_check::<f32>(&ColumnType::Float, make_bytes(&(-123f32).to_be_bytes()));
1944-
compat_check::<f64>(&ColumnType::Double, make_bytes(&123f64.to_be_bytes()));
1945-
compat_check::<f64>(&ColumnType::Double, make_bytes(&(-123f64).to_be_bytes()));
1946-
1947-
// big integers
1948-
const PI_STR: &[u8] = b"3.1415926535897932384626433832795028841971693993751058209749445923";
1949-
let num1 = &PI_STR[2..];
1950-
let num2 = [b'-']
1951-
.into_iter()
1952-
.chain(PI_STR[2..].iter().copied())
1953-
.collect::<Vec<_>>();
1954-
let num3 = &b"0"[..];
1955-
1956-
// native - CqlVarint
1957-
{
1958-
let num1 = CqlVarint::from_signed_bytes_be_slice(num1);
1959-
let num2 = CqlVarint::from_signed_bytes_be_slice(&num2);
1960-
let num3 = CqlVarint::from_signed_bytes_be_slice(num3);
1961-
compat_check_serialized::<CqlVarint>(&ColumnType::Varint, &num1);
1962-
compat_check_serialized::<CqlVarint>(&ColumnType::Varint, &num2);
1963-
compat_check_serialized::<CqlVarint>(&ColumnType::Varint, &num3);
1964-
}
1965-
1966-
#[cfg(feature = "num-bigint-03")]
1967-
{
1968-
use num_bigint_03::BigInt;
1969-
1970-
let num1 = BigInt::parse_bytes(num1, 10).unwrap();
1971-
let num2 = BigInt::parse_bytes(&num2, 10).unwrap();
1972-
let num3 = BigInt::parse_bytes(num3, 10).unwrap();
1973-
compat_check_serialized::<BigInt>(&ColumnType::Varint, &num1);
1974-
compat_check_serialized::<BigInt>(&ColumnType::Varint, &num2);
1975-
compat_check_serialized::<BigInt>(&ColumnType::Varint, &num3);
1976-
}
1977-
1978-
#[cfg(feature = "num-bigint-04")]
1979-
{
1980-
use num_bigint_04::BigInt;
1981-
1982-
let num1 = BigInt::parse_bytes(num1, 10).unwrap();
1983-
let num2 = BigInt::parse_bytes(&num2, 10).unwrap();
1984-
let num3 = BigInt::parse_bytes(num3, 10).unwrap();
1985-
compat_check_serialized::<BigInt>(&ColumnType::Varint, &num1);
1986-
compat_check_serialized::<BigInt>(&ColumnType::Varint, &num2);
1987-
compat_check_serialized::<BigInt>(&ColumnType::Varint, &num3);
1988-
}
1989-
1990-
// big decimals
1991-
{
1992-
let scale1 = 0;
1993-
let scale2 = -42;
1994-
let scale3 = 2137;
1995-
let num1 = CqlDecimal::from_signed_be_bytes_slice_and_exponent(num1, scale1);
1996-
let num2 = CqlDecimal::from_signed_be_bytes_and_exponent(num2, scale2);
1997-
let num3 = CqlDecimal::from_signed_be_bytes_slice_and_exponent(num3, scale3);
1998-
compat_check_serialized::<CqlDecimal>(&ColumnType::Decimal, &num1);
1999-
compat_check_serialized::<CqlDecimal>(&ColumnType::Decimal, &num2);
2000-
compat_check_serialized::<CqlDecimal>(&ColumnType::Decimal, &num3);
2001-
}
2002-
2003-
// native - CqlDecimal
2004-
2005-
#[cfg(feature = "bigdecimal-04")]
2006-
{
2007-
use bigdecimal_04::BigDecimal;
2008-
2009-
let num1 = PI_STR.to_vec();
2010-
let num2 = vec![b'-']
2011-
.into_iter()
2012-
.chain(PI_STR.iter().copied())
2013-
.collect::<Vec<_>>();
2014-
let num3 = b"0.0".to_vec();
2015-
2016-
let num1 = BigDecimal::parse_bytes(&num1, 10).unwrap();
2017-
let num2 = BigDecimal::parse_bytes(&num2, 10).unwrap();
2018-
let num3 = BigDecimal::parse_bytes(&num3, 10).unwrap();
2019-
compat_check_serialized::<BigDecimal>(&ColumnType::Decimal, &num1);
2020-
compat_check_serialized::<BigDecimal>(&ColumnType::Decimal, &num2);
2021-
compat_check_serialized::<BigDecimal>(&ColumnType::Decimal, &num3);
2022-
}
2023-
2024-
// blob
2025-
compat_check::<Vec<u8>>(&ColumnType::Blob, make_bytes(&[]));
2026-
compat_check::<Vec<u8>>(&ColumnType::Blob, make_bytes(&[1, 9, 2, 8, 3, 7, 4, 6, 5]));
2027-
2028-
// text types
2029-
for typ in &[ColumnType::Ascii, ColumnType::Text] {
2030-
compat_check::<String>(typ, make_bytes("".as_bytes()));
2031-
compat_check::<String>(typ, make_bytes("foo".as_bytes()));
2032-
compat_check::<String>(typ, make_bytes("superfragilisticexpialidocious".as_bytes()));
2033-
}
2034-
2035-
// counters
2036-
for i in 0..63 {
2037-
let v: i64 = 1 << i;
2038-
compat_check::<Counter>(&ColumnType::Counter, make_bytes(&v.to_be_bytes()));
2039-
}
2040-
2041-
// duration
2042-
let duration1 = CqlDuration {
2043-
days: 123,
2044-
months: 456,
2045-
nanoseconds: 789,
2046-
};
2047-
let duration2 = CqlDuration {
2048-
days: 987,
2049-
months: 654,
2050-
nanoseconds: 321,
2051-
};
2052-
compat_check_serialized::<CqlDuration>(&ColumnType::Duration, &duration1);
2053-
compat_check_serialized::<CqlDuration>(&ColumnType::Duration, &duration2);
2054-
2055-
// date
2056-
let date1 = (2u32.pow(31)).to_be_bytes();
2057-
let date2 = (2u32.pow(31) - 30).to_be_bytes();
2058-
let date3 = (2u32.pow(31) + 30).to_be_bytes();
2059-
2060-
compat_check::<CqlDate>(&ColumnType::Date, make_bytes(&date1));
2061-
compat_check::<CqlDate>(&ColumnType::Date, make_bytes(&date2));
2062-
compat_check::<CqlDate>(&ColumnType::Date, make_bytes(&date3));
2063-
2064-
#[cfg(feature = "chrono")]
2065-
{
2066-
compat_check::<chrono::NaiveDate>(&ColumnType::Date, make_bytes(&date1));
2067-
compat_check::<chrono::NaiveDate>(&ColumnType::Date, make_bytes(&date2));
2068-
compat_check::<chrono::NaiveDate>(&ColumnType::Date, make_bytes(&date3));
2069-
}
2070-
2071-
#[cfg(feature = "time")]
2072-
{
2073-
compat_check::<time::Date>(&ColumnType::Date, make_bytes(&date1));
2074-
compat_check::<time::Date>(&ColumnType::Date, make_bytes(&date2));
2075-
compat_check::<time::Date>(&ColumnType::Date, make_bytes(&date3));
2076-
}
2077-
2078-
// time
2079-
let time1 = CqlTime(0);
2080-
let time2 = CqlTime(123456789);
2081-
let time3 = CqlTime(86399999999999); // maximum allowed
2082-
2083-
compat_check_serialized::<CqlTime>(&ColumnType::Time, &time1);
2084-
compat_check_serialized::<CqlTime>(&ColumnType::Time, &time2);
2085-
compat_check_serialized::<CqlTime>(&ColumnType::Time, &time3);
2086-
2087-
#[cfg(feature = "chrono")]
2088-
{
2089-
compat_check_serialized::<chrono::NaiveTime>(&ColumnType::Time, &time1);
2090-
compat_check_serialized::<chrono::NaiveTime>(&ColumnType::Time, &time2);
2091-
compat_check_serialized::<chrono::NaiveTime>(&ColumnType::Time, &time3);
2092-
}
2093-
2094-
#[cfg(feature = "time")]
2095-
{
2096-
compat_check_serialized::<time::Time>(&ColumnType::Time, &time1);
2097-
compat_check_serialized::<time::Time>(&ColumnType::Time, &time2);
2098-
compat_check_serialized::<time::Time>(&ColumnType::Time, &time3);
2099-
}
2100-
2101-
// timestamp
2102-
let timestamp1 = CqlTimestamp(0);
2103-
let timestamp2 = CqlTimestamp(123456789);
2104-
let timestamp3 = CqlTimestamp(98765432123456);
2105-
2106-
compat_check_serialized::<CqlTimestamp>(&ColumnType::Timestamp, &timestamp1);
2107-
compat_check_serialized::<CqlTimestamp>(&ColumnType::Timestamp, &timestamp2);
2108-
compat_check_serialized::<CqlTimestamp>(&ColumnType::Timestamp, &timestamp3);
2109-
2110-
#[cfg(feature = "chrono")]
2111-
{
2112-
compat_check_serialized::<chrono::DateTime<chrono::Utc>>(
2113-
&ColumnType::Timestamp,
2114-
&timestamp1,
2115-
);
2116-
compat_check_serialized::<chrono::DateTime<chrono::Utc>>(
2117-
&ColumnType::Timestamp,
2118-
&timestamp2,
2119-
);
2120-
compat_check_serialized::<chrono::DateTime<chrono::Utc>>(
2121-
&ColumnType::Timestamp,
2122-
&timestamp3,
2123-
);
2124-
}
2125-
2126-
#[cfg(feature = "time")]
2127-
{
2128-
compat_check_serialized::<time::OffsetDateTime>(&ColumnType::Timestamp, &timestamp1);
2129-
compat_check_serialized::<time::OffsetDateTime>(&ColumnType::Timestamp, &timestamp2);
2130-
compat_check_serialized::<time::OffsetDateTime>(&ColumnType::Timestamp, &timestamp3);
2131-
}
2132-
2133-
// inet
2134-
let ipv4 = IpAddr::from([127u8, 0, 0, 1]);
2135-
let ipv6: IpAddr = Ipv6Addr::LOCALHOST.into();
2136-
compat_check::<IpAddr>(&ColumnType::Inet, make_ip_address(ipv4));
2137-
compat_check::<IpAddr>(&ColumnType::Inet, make_ip_address(ipv6));
2138-
2139-
// uuid and timeuuid
2140-
// new_v4 generates random UUIDs, so these are different cases
2141-
for uuid in std::iter::repeat_with(Uuid::new_v4).take(3) {
2142-
compat_check_serialized::<Uuid>(&ColumnType::Uuid, &uuid);
2143-
compat_check_serialized::<CqlTimeuuid>(&ColumnType::Timeuuid, &CqlTimeuuid::from(uuid));
2144-
}
2145-
2146-
// empty values
2147-
// ...are implemented via MaybeEmpty and are handled in other tests
2148-
2149-
// nulls, represented via Option
2150-
compat_check_serialized::<Option<i32>>(&ColumnType::Int, &123i32);
2151-
compat_check::<Option<i32>>(&ColumnType::Int, make_null());
2152-
2153-
// collections
2154-
let mut list = BytesMut::new();
2155-
list.put_i32(3);
2156-
append_bytes(&mut list, &123i32.to_be_bytes());
2157-
append_bytes(&mut list, &456i32.to_be_bytes());
2158-
append_bytes(&mut list, &789i32.to_be_bytes());
2159-
let list = make_bytes(&list);
2160-
let list_type = ColumnType::List(Box::new(ColumnType::Int));
2161-
compat_check::<Vec<i32>>(&list_type, list.clone());
2162-
// Support for deserialization List -> {Hash,BTree}Set was removed not to cause confusion.
2163-
// Such deserialization would be lossy, which is unwanted.
2164-
2165-
let mut set = BytesMut::new();
2166-
set.put_i32(3);
2167-
append_bytes(&mut set, &123i32.to_be_bytes());
2168-
append_bytes(&mut set, &456i32.to_be_bytes());
2169-
append_bytes(&mut set, &789i32.to_be_bytes());
2170-
let set = make_bytes(&set);
2171-
let set_type = ColumnType::Set(Box::new(ColumnType::Int));
2172-
compat_check::<Vec<i32>>(&set_type, set.clone());
2173-
compat_check::<BTreeSet<i32>>(&set_type, set.clone());
2174-
compat_check::<HashSet<i32>>(&set_type, set);
2175-
2176-
let mut map = BytesMut::new();
2177-
map.put_i32(3);
2178-
append_bytes(&mut map, &123i32.to_be_bytes());
2179-
append_bytes(&mut map, "quick".as_bytes());
2180-
append_bytes(&mut map, &456i32.to_be_bytes());
2181-
append_bytes(&mut map, "brown".as_bytes());
2182-
append_bytes(&mut map, &789i32.to_be_bytes());
2183-
append_bytes(&mut map, "fox".as_bytes());
2184-
let map = make_bytes(&map);
2185-
let map_type = ColumnType::Map(Box::new(ColumnType::Int), Box::new(ColumnType::Text));
2186-
compat_check::<BTreeMap<i32, String>>(&map_type, map.clone());
2187-
compat_check::<HashMap<i32, String>>(&map_type, map);
2188-
}
2189-
21901908
#[test]
21911909
fn test_maybe_empty() {
21921910
let empty = make_bytes(&[]);
@@ -2348,37 +2066,6 @@ pub(super) mod tests {
23482066
assert_eq!(tup, SwappedPair("foo", 42));
23492067
}
23502068

2351-
// Checks that both new and old serialization framework
2352-
// produces the same results in this case
2353-
fn compat_check<T>(typ: &ColumnType, raw: Bytes)
2354-
where
2355-
T: for<'f> DeserializeValue<'f>,
2356-
T: FromCqlVal<Option<CqlValue>>,
2357-
T: Debug + PartialEq,
2358-
{
2359-
let mut slice = raw.as_ref();
2360-
let mut cell = types::read_bytes_opt(&mut slice).unwrap();
2361-
let old = T::from_cql(
2362-
cell.as_mut()
2363-
.map(|c| deser_cql_value(typ, c))
2364-
.transpose()
2365-
.unwrap(),
2366-
)
2367-
.unwrap();
2368-
let new = deserialize::<T>(typ, &raw).unwrap();
2369-
assert_eq!(old, new);
2370-
}
2371-
2372-
fn compat_check_serialized<T>(typ: &ColumnType, val: &dyn SerializeValue)
2373-
where
2374-
T: for<'f> DeserializeValue<'f>,
2375-
T: FromCqlVal<Option<CqlValue>>,
2376-
T: Debug + PartialEq,
2377-
{
2378-
let raw = serialize(typ, val);
2379-
compat_check::<T>(typ, raw);
2380-
}
2381-
23822069
fn deserialize<'frame, T>(
23832070
typ: &'frame ColumnType,
23842071
bytes: &'frame Bytes,

0 commit comments

Comments
 (0)