Skip to content

Commit ebbac62

Browse files
committed
value: test null and empty
1 parent bd6196c commit ebbac62

File tree

1 file changed

+29
-1
lines changed
  • scylla-cql/src/types/deserialize

1 file changed

+29
-1
lines changed

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

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -845,7 +845,7 @@ mod tests {
845845
use crate::types::serialize::value::SerializeValue;
846846
use crate::types::serialize::CellWriter;
847847

848-
use super::{mk_deser_err, BuiltinDeserializationErrorKind, DeserializeValue};
848+
use super::{mk_deser_err, BuiltinDeserializationErrorKind, DeserializeValue, MaybeEmpty};
849849

850850
#[test]
851851
fn test_deserialize_bytes() {
@@ -934,6 +934,34 @@ mod tests {
934934
assert_eq!(decoded_double, 2.0);
935935
}
936936

937+
#[test]
938+
fn test_null_and_empty() {
939+
// non-nullable emptiable deserialization, non-empty value
940+
let int = make_bytes(&[21, 37, 0, 0]);
941+
let decoded_int = deserialize::<MaybeEmpty<i32>>(&ColumnType::Int, &int).unwrap();
942+
assert_eq!(decoded_int, MaybeEmpty::Value((21 << 24) + (37 << 16)));
943+
944+
// non-nullable emptiable deserialization, empty value
945+
let int = make_bytes(&[]);
946+
let decoded_int = deserialize::<MaybeEmpty<i32>>(&ColumnType::Int, &int).unwrap();
947+
assert_eq!(decoded_int, MaybeEmpty::Empty);
948+
949+
// nullable non-emptiable deserialization, non-null value
950+
let int = make_bytes(&[21, 37, 0, 0]);
951+
let decoded_int = deserialize::<Option<i32>>(&ColumnType::Int, &int).unwrap();
952+
assert_eq!(decoded_int, Some((21 << 24) + (37 << 16)));
953+
954+
// nullable non-emptiable deserialization, null value
955+
let int = make_null();
956+
let decoded_int = deserialize::<Option<i32>>(&ColumnType::Int, &int).unwrap();
957+
assert_eq!(decoded_int, None);
958+
959+
// nullable emptiable deserialization, non-null non-empty value
960+
let int = make_bytes(&[]);
961+
let decoded_int = deserialize::<Option<MaybeEmpty<i32>>>(&ColumnType::Int, &int).unwrap();
962+
assert_eq!(decoded_int, Some(MaybeEmpty::Empty));
963+
}
964+
937965
#[test]
938966
fn test_from_cql_value_compatibility() {
939967
// This test should have a sub-case for each type

0 commit comments

Comments
 (0)