fn main()
{
println!( "\n=== Testing All readme.md Examples ===" );
test_tempdir_raii();
test_glob_pattern_matching();
test_recursive_glob();
test_pattern_matching();
println!( "\n✓ All readme.md examples completed successfully\n" );
}
#[ cfg( feature = "enabled" ) ]
fn test_tempdir_raii()
{
use fs_tools::TempDir;
use std::path::PathBuf;
println!( "\n--- Test 1: TempDir with RAII Cleanup ---" );
let mut temp = TempDir::new();
temp.base_path = std::env::temp_dir();
temp.prefix_path = PathBuf::from( "my_app" );
temp.postfix_path = PathBuf::from( "session_1" );
let path = temp.create_all().expect( "failed to create" );
println!( "Created: {}", path.display() );
assert!( path.is_dir(), "Directory should exist after creation" );
assert!( path.exists(), "Path should exist" );
println!( "✓ Directory exists and is a directory" );
}
#[ cfg( not( feature = "enabled" ) ) ]
fn test_tempdir_raii()
{
println!( "\n--- Test 1: TempDir with RAII Cleanup ---" );
println!( "⚠ Skipped (requires 'enabled' feature)" );
}
#[ cfg( feature = "glob" ) ]
fn test_glob_pattern_matching()
{
use fs_tools::glob::glob;
println!( "\n--- Test 2: Glob Pattern Matching ---" );
let mut found_count = 0;
for path in glob( "*.rs" ).expect( "valid pattern" ).flatten()
{
println!( "Found: {}", path.display() );
found_count += 1;
}
println!( "✓ Found {found_count} .rs files" );
}
#[ cfg( not( feature = "glob" ) ) ]
fn test_glob_pattern_matching()
{
println!( "\n--- Test 2: Glob Pattern Matching ---" );
println!( "⚠ Skipped (requires 'glob' feature)" );
}
#[ cfg( feature = "glob" ) ]
fn test_recursive_glob()
{
use fs_tools::glob::glob;
println!( "\n--- Test 3: Recursive Glob ---" );
let mut found_count = 0;
for path in glob( "src/**/*.rs" ).expect( "valid pattern" ).flatten()
{
println!( "Found: {}", path.display() );
found_count += 1;
}
println!( "✓ Found {found_count} .rs files recursively" );
}
#[ cfg( not( feature = "glob" ) ) ]
fn test_recursive_glob()
{
println!( "\n--- Test 3: Recursive Glob ---" );
println!( "⚠ Skipped (requires 'glob' feature)" );
}
#[ cfg( feature = "glob" ) ]
fn test_pattern_matching()
{
use fs_tools::glob::Pattern;
println!( "\n--- Test 4: Pattern Matching ---" );
let pattern = Pattern::new( "*.rs" ).expect( "valid pattern" );
assert!( pattern.matches( "lib.rs" ), "Should match lib.rs" );
assert!( !pattern.matches( "Cargo.toml" ), "Should not match Cargo.toml" );
println!( "✓ Pattern matching works correctly" );
}
#[ cfg( not( feature = "glob" ) ) ]
fn test_pattern_matching()
{
println!( "\n--- Test 4: Pattern Matching ---" );
println!( "⚠ Skipped (requires 'glob' feature)" );
}