From 2b9023e1805176276180ba59ea865093382efb0c Mon Sep 17 00:00:00 2001 From: figsoda Date: Thu, 4 Nov 2021 17:03:52 -0400 Subject: [PATCH] misc comments and wording changes --- tests/integration.rs | 19 ++++++++++++++----- tests/mime.rs | 4 ++-- tests/utils.rs | 5 ++++- 3 files changed, 20 insertions(+), 8 deletions(-) diff --git a/tests/integration.rs b/tests/integration.rs index 3929378..53eecd3 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -10,10 +10,11 @@ use rand::{rngs::SmallRng, RngCore, SeedableRng}; use tempfile::tempdir; use test_strategy::{proptest, Arbitrary}; -use crate::utils::{assert_same_directory, create_file_random}; +use crate::utils::{assert_same_directory, write_random_content}; +// tar and zip extensions #[derive(Arbitrary, Debug, Display)] -#[display(style = "snake_case")] +#[display(style = "lowercase")] enum DirectoryExtension { Tar, Tbz, @@ -25,8 +26,9 @@ enum DirectoryExtension { Zip, } +// extensions of single file compression formats #[derive(Arbitrary, Debug, Display)] -#[display(style = "snake_case")] +#[display(style = "lowercase")] enum FileExtension { Bz, Bz2, @@ -44,10 +46,12 @@ enum Extension { File(FileExtension), } +// converts a list of extension structs to string fn merge_extensions(ext: impl ToString, exts: Vec) -> String { once(ext.to_string()).chain(exts.into_iter().map(|x| x.to_string())).collect::>().join(".") } +// create random nested directories and files under the specified directory fn create_random_files(dir: impl Into, depth: u8, rng: &mut SmallRng) { if depth == 0 { return; @@ -55,15 +59,18 @@ fn create_random_files(dir: impl Into, depth: u8, rng: &mut SmallRng) { let dir = &dir.into(); + // create 0 to 7 random files for _ in 0..rng.next_u32() % 8 { - create_file_random(&mut tempfile::Builder::new().tempfile_in(dir).unwrap().keep().unwrap().0, rng); + write_random_content(&mut tempfile::Builder::new().tempfile_in(dir).unwrap().keep().unwrap().0, rng); } + // create more random files in 0 to 3 new directories for _ in 0..rng.next_u32() % 4 { create_random_files(&tempfile::tempdir_in(dir).unwrap().into_path(), depth - 1, rng); } } +// compress and decompress a single empty file #[proptest(cases = 512)] fn single_empty_file(ext: Extension, #[any(size_range(0..8).lift())] exts: Vec) { let dir = tempdir().unwrap(); @@ -73,12 +80,13 @@ fn single_empty_file(ext: Extension, #[any(size_range(0..8).lift())] exts: Vec) { let dir = tempdir().unwrap(); @@ -94,6 +102,7 @@ fn single_file(ext: Extension, #[any(size_range(0..8).lift())] exts: Vec, y: impl Into, preserve_permissions: bool) { fn read_dir(dir: impl Into) -> impl Iterator { let mut dir: Vec<_> = fs::read_dir(dir).unwrap().map(|entry| entry.unwrap()).collect();