Skip to content

Commit

Permalink
serialize: tests for dyn SerializeCql/dyn SerializeRow
Browse files Browse the repository at this point in the history
As a final confirmation of the work in the PR and to prevent
regressions, add tests which explicitly use `dyn SerializeCql` and
`dyn SerializeRow`.
  • Loading branch information
piodul committed Dec 8, 2023
1 parent 6a1ea41 commit 5733a2f
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 0 deletions.
33 changes: 33 additions & 0 deletions scylla-cql/src/types/serialize/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -639,4 +639,37 @@ mod tests {
// Skip the value count
assert_eq!(&sorted_row_data[2..], unsorted_row_data);
}

#[test]
fn test_dyn_serialize_row() {
let row = (
1i32,
"Ala ma kota",
None::<i64>,
MaybeUnset::Unset::<String>,
);
let ctx = RowSerializationContext {
columns: &[
col_spec("a", ColumnType::Int),
col_spec("b", ColumnType::Text),
col_spec("c", ColumnType::BigInt),
col_spec("d", ColumnType::Ascii),
],
};

let mut typed_data = Vec::new();
let mut typed_data_writer = RowWriter::new(&mut typed_data);
<_ as SerializeRow>::serialize(&row, &ctx, &mut typed_data_writer).unwrap();

let row = &row as &dyn SerializeRow;
let mut erased_data = Vec::new();
let mut erased_data_writer = RowWriter::new(&mut erased_data);
<_ as SerializeRow>::serialize(&row, &ctx, &mut erased_data_writer).unwrap();

assert_eq!(
typed_data_writer.value_count(),
erased_data_writer.value_count(),
);
assert_eq!(typed_data, erased_data);
}
}
15 changes: 15 additions & 0 deletions scylla-cql/src/types/serialize/value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1392,4 +1392,19 @@ mod tests {
check_compat(None::<i32>);
check_compat(MaybeUnset::Unset::<i32>);
}

#[test]
fn test_dyn_serialize_cql() {
let v: i32 = 123;
let mut typed_data = Vec::new();
let typed_data_writer = CellWriter::new(&mut typed_data);
<_ as SerializeCql>::serialize(&v, &ColumnType::Int, typed_data_writer).unwrap();

let v = &v as &dyn SerializeCql;
let mut erased_data = Vec::new();
let erased_data_writer = CellWriter::new(&mut erased_data);
<_ as SerializeCql>::serialize(&v, &ColumnType::Int, erased_data_writer).unwrap();

assert_eq!(typed_data, erased_data);
}
}

0 comments on commit 5733a2f

Please sign in to comment.