Skip to content

Commit

Permalink
tests: Unit test Archive::get_bytes_via_table
Browse files Browse the repository at this point in the history
Inroduce the following unit test functions:
 - tests::archive_get_bytes_via_table
 - tests::archive_get_bytes_via_table_empty
  • Loading branch information
phrohdoh committed Feb 4, 2018
1 parent 19eaf98 commit b2733ec
Showing 1 changed file with 42 additions and 0 deletions.
42 changes: 42 additions & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -544,4 +544,46 @@ mod tests {
assert!(table.contains_key(name2));
assert!(!table.contains_key("some/other/key.ini"));
}

#[test]
fn archive_get_bytes_via_table() {
let name = "first/entry.txt";
let data = [0, 1, 2, 3];

let entries = vec![(name.into(), &data[..])];

let mut archive = packer::pack(entries, Kind::BigF).unwrap();

let table = archive.read_entry_metadata_table();
assert!(table.is_ok());
let table = table.unwrap();
assert!(table.contains_key(name));

let bytes = archive.get_bytes_via_table(&table, name);
assert!(bytes.is_some());

let bytes = bytes.unwrap();
assert_eq!(data, bytes);
}

#[test]
fn archive_get_bytes_via_table_empty() {
let name = "first/entry.txt";
let data: [u8; 0] = [];

let entries = vec![(name.into(), &data[..])];

let mut archive = packer::pack(entries, Kind::BigF).unwrap();

let table = archive.read_entry_metadata_table();
assert!(table.is_ok());
let table = table.unwrap();
assert!(table.contains_key(name));

let bytes = archive.get_bytes_via_table(&table, name);
assert!(bytes.is_some());

let bytes = bytes.unwrap();
assert!(bytes.is_empty());
}
}

0 comments on commit b2733ec

Please sign in to comment.