#![allow(dead_code)]
use proptest::prelude::*;
use super::options::ProcessorOptions;
use super::virtual_fs::VirtualFile;
use crate::format::OutputFormat;
fn path_component() -> impl Strategy<Value = String> {
prop::string::string_regex("[a-zA-Z_][a-zA-Z0-9_.\\-]{0,30}").unwrap()
}
pub fn valid_path() -> impl Strategy<Value = String> {
prop::collection::vec(path_component(), 1..=5).prop_map(|parts| parts.join("/"))
}
pub fn dotfile_path() -> impl Strategy<Value = String> {
(
prop::collection::vec(path_component(), 0..=3),
prop::string::string_regex("\\.[a-zA-Z][a-zA-Z0-9_]{0,15}").unwrap(),
prop::collection::vec(path_component(), 0..=2),
)
.prop_map(|(prefix, dot_component, suffix)| {
let mut parts = prefix;
parts.push(dot_component);
parts.extend(suffix);
parts.join("/")
})
}
pub fn file_content() -> impl Strategy<Value = String> {
prop::string::string_regex("[\\s\\S]{0,500}").unwrap()
}
pub fn virtual_file() -> impl Strategy<Value = VirtualFile> {
(valid_path(), file_content())
.prop_map(|(path, content)| VirtualFile::new_unchecked(path, content))
}
pub fn virtual_files(max: usize) -> impl Strategy<Value = Vec<VirtualFile>> {
prop::collection::vec(virtual_file(), 0..=max)
}
pub fn extension() -> impl Strategy<Value = String> {
prop::string::string_regex("[a-z]{1,8}").unwrap()
}
fn glob_pattern() -> impl Strategy<Value = String> {
prop_oneof![
Just("**/target/**".to_string()),
Just("*.lock".to_string()),
Just("dist/**".to_string()),
Just("**/node_modules/**".to_string()),
Just("**/*.min.js".to_string()),
path_component().prop_map(|c| format!("**/{c}/**")),
extension().prop_map(|e| format!("*.{e}")),
]
}
pub fn processor_options() -> impl Strategy<Value = ProcessorOptions> {
(
prop::bool::ANY, prop::option::of(1..500usize), prop::option::of(64..100_000usize), prop::collection::vec(extension(), 0..=5), prop::collection::vec(glob_pattern(), 0..=3), prop_oneof![Just(OutputFormat::Markdown), Just(OutputFormat::Tree)],
)
.prop_map(
|(
include_dotfiles,
max_files,
max_output_bytes,
ignore_extensions,
ignore_globs,
output_format,
)| {
let mut builder = ProcessorOptions::builder()
.output_format(output_format)
.ignore_extensions(ignore_extensions)
.ignore_globs(ignore_globs)
.include_dotfiles(include_dotfiles);
if let Some(max) = max_files {
builder = builder.max_files(max);
}
if let Some(max) = max_output_bytes {
builder = builder.max_output_bytes(max);
}
builder.build().expect("generated globs are always valid")
},
)
}