Skip to content

Commit

Permalink
tests: add test for reading unicode header
Browse files Browse the repository at this point in the history
  • Loading branch information
muja committed Sep 7, 2024
1 parent 1ccff4a commit 9b6703b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Binary file added data/unicode-entry.rar
Binary file not shown.
25 changes: 25 additions & 0 deletions tests/utf8.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,28 @@ fn unicode_extract_with_base() {
assert_eq!("unrar-0.4.0", std::fs::read_to_string(unicode_dir.join("VERSION")).expect("read failed"));
}

#[test]
fn unicode_entry() {
let archive = Archive::new("data/unicode-entry.rar").open_for_listing().unwrap();
let archive = archive.read_header().unwrap().unwrap();
assert_eq!(archive.entry().filename.as_os_str(), "unicodefilename❤️.txt");
}

#[test]
fn unicode_entry_process_mode() {
let archive = Archive::new("data/unicode-entry.rar").open_for_processing().unwrap();
let archive = archive.read_header().unwrap().unwrap();
assert_eq!(archive.entry().filename.as_os_str(), "unicodefilename❤️.txt");
assert_eq!(&String::from_utf8(archive.read().unwrap().0).unwrap(), "foobar\n");
}

#[test]
fn unicode_entry_extract() {
let parent = tempfile::tempdir().unwrap();
let archive = Archive::new("data/unicode-entry.rar").open_for_processing().unwrap();
let archive = archive.read_header().unwrap().unwrap();
archive.extract_with_base(&parent).expect("extract");
let entries = std::fs::read_dir(&parent).expect("read_dir").collect::<Result<Vec<_>, _>>().expect("read_dir[0]");
assert_eq!(entries.len(), 1);
assert_eq!(&entries[0].file_name(), "unicodefilename❤️.txt");
}

0 comments on commit 9b6703b

Please sign in to comment.