Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 37 additions & 1 deletion core/src/data/key.rs
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ impl Key {
mod tests {
use {
crate::{
data::{Key, KeyError, Value},
data::{Interval, Key, KeyError, Value},
executor::evaluate_stateless,
parse_sql::parse_expr,
result::Result,
Expand Down Expand Up @@ -383,6 +383,42 @@ mod tests {
size_l.cmp(&size_r)
}

#[test]
fn key_partial_cmp() {
use uuid::Uuid;
macro_rules! equal {
($expr: expr) => {
assert_eq!(&$expr.partial_cmp(&$expr), &Some(Ordering::Equal))
};
}
equal!(Key::Bool(true));
equal!(Key::I8(11));
equal!(Key::I16(11));
equal!(Key::I32(11));
equal!(Key::I64(2048));
equal!(Key::U8(11));
equal!(Key::U16(11));
equal!(Key::Decimal(Decimal::from_str("123.45").unwrap()));

equal!(Key::Str("Hello World".to_owned()));
equal!(Key::Bytea(hex::decode("1234").unwrap()));
equal!(Key::Date(NaiveDate::from_ymd_opt(2021, 1, 1).unwrap()));
equal!(Key::Time(
NaiveTime::from_hms_milli_opt(20, 1, 9, 100).unwrap()
));
equal!(Key::Timestamp(
NaiveDateTime::from_timestamp_millis(1662921288).unwrap()
));
equal!(Key::Interval(Interval::Month(30)));
equal!(Key::Uuid(
Uuid::parse_str("550e8400-e29b-41d4-a716-446655440000")
.unwrap()
.as_u128()
));
// None
assert_eq!(&Key::None.partial_cmp(&Key::None), &None);
}

#[test]
fn cmp_big_endian() {
use crate::data::{Interval as I, Key::*};
Expand Down
9 changes: 9 additions & 0 deletions core/src/data/value/convert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -656,6 +656,7 @@ mod tests {
test!(Value::U16(2), Err(ValueError::ImpossibleCast.into()));
test!(Value::F64(1.0), Ok(true));
test!(Value::F64(0.0), Ok(false));
test!(Value::F64(2.0), Err(ValueError::ImpossibleCast.into()));
test!(Value::Str("true".to_owned()), Ok(true));
test!(Value::Str("false".to_owned()), Ok(false));
test!(Value::Decimal(Decimal::new(10, 1)), Ok(true));
Expand Down Expand Up @@ -1262,6 +1263,7 @@ mod tests {
Ok(date(2021, 11, 20))
);
test!(&Value::Str("2021-11-20".to_owned()), Ok(date(2021, 11, 20)));
test!(&Value::F64(1.0), Err(ValueError::ImpossibleCast.into()));
}

#[test]
Expand All @@ -1275,6 +1277,7 @@ mod tests {

test!(&Value::Time(time(10, 0, 0, 0)), Ok(time(10, 0, 0, 0)));
test!(&Value::Str("10:00:00".to_owned()), Ok(time(10, 0, 0, 0)));
test!(&Value::F64(1.0), Err(ValueError::ImpossibleCast.into()));
}

#[test]
Expand All @@ -1299,6 +1302,7 @@ mod tests {
&Value::Str("2021-11-20".to_owned()),
Ok(datetime(date(2021, 11, 20), time(0, 0, 0, 0)))
);
test!(&Value::F64(1.0), Err(ValueError::ImpossibleCast.into()));
}

#[test]
Expand All @@ -1311,6 +1315,10 @@ mod tests {
I::try_from(&Value::Str("'+22-10' YEAR TO MONTH".to_owned())),
Ok(I::Month(274))
);
assert_eq!(
I::try_from(&Value::F64(1.0)),
Err(ValueError::ImpossibleCast.into())
);
}

#[test]
Expand Down Expand Up @@ -1357,6 +1365,7 @@ mod tests {
assert_eq!(IpAddr::try_from($from), Ok(IpAddr::from_str($to).unwrap()))
};
}
test!(&Value::Inet(IpAddr::from_str("::1").unwrap()), "::1");
test!(&Value::Str("127.0.0.1".to_owned()), "127.0.0.1");
test!(&Value::Str("0.0.0.0".to_owned()), "0.0.0.0");
test!(IpAddr::from_str("::1").unwrap(), "::1");
Expand Down