Add test for zero copy

This commit is contained in:
Ajeet D'Souza 2021-03-26 18:36:49 +05:30
parent 6a67e9444c
commit 99ee250868
2 changed files with 32 additions and 3 deletions

12
.gitignore vendored
View File

@ -1,7 +1,13 @@
# Generated by Cargo
# will have compiled files and executables
### Custom ###
.vscode/
### Rust ###
# Compiled files and executables
debug/
target/
# These are backup files generated by rustfmt
# Backup files generated by rustfmt
**/*.rs.bk
### Python ###
.mypy_cache/

View File

@ -163,3 +163,26 @@ impl Display for DirDisplayScore<'_> {
pub type Rank = f64;
pub type Epoch = u64;
#[cfg(test)]
mod tests {
use super::{Dir, DirList};
use std::borrow::Cow;
#[test]
fn zero_copy() {
let dirs = DirList(vec![Dir {
path: "/".into(),
rank: 0.0,
last_accessed: 0,
}]);
let bytes = dirs.to_bytes().unwrap();
let dirs = DirList::from_bytes(&bytes).unwrap();
for dir in dirs.iter() {
assert!(matches!(dir.path, Cow::Borrowed(_)))
}
}
}