mod common;
use archive::{ArchiveExtractor, ArchiveFormat};
use common::{assert_contains_file, read_test_archive};
#[test]
fn test_verify_file_contents() {
let data = read_test_archive("basic.zip");
let extractor = ArchiveExtractor::new();
let files = extractor
.extract(&data, ArchiveFormat::Zip)
.expect("Failed to extract basic.zip");
let hello_file = assert_contains_file(&files, "hello.txt");
let content = String::from_utf8_lossy(&hello_file.data);
assert_eq!(content.trim(), "Hello, World!", "Unexpected file content");
}
#[test]
fn test_nested_directory_structure() {
let data = read_test_archive("basic.zip");
let extractor = ArchiveExtractor::new();
let files = extractor
.extract(&data, ArchiveFormat::Zip)
.expect("Failed to extract basic.zip");
assert_contains_file(&files, "nested/deep/path/deep-file.txt");
}
#[test]
fn test_binary_file_extraction() {
let data = read_test_archive("basic.zip");
let extractor = ArchiveExtractor::new();
let files = extractor
.extract(&data, ArchiveFormat::Zip)
.expect("Failed to extract basic.zip");
let binary_file = assert_contains_file(&files, "binary.bin");
assert_eq!(
binary_file.data.len(),
10 * 1024,
"Expected 10KB binary file"
);
}
#[test]
fn test_large_file_extraction() {
let data = read_test_archive("basic.zip");
let extractor = ArchiveExtractor::new();
let files = extractor
.extract(&data, ArchiveFormat::Zip)
.expect("Failed to extract basic.zip");
let large_file = assert_contains_file(&files, "large-file.bin");
assert_eq!(large_file.data.len(), 1024 * 1024, "Expected 1MB file");
}