use std::fs;
use std::path::PathBuf;
fn examples_dir() -> PathBuf
{
let manifest_dir = env!( "CARGO_MANIFEST_DIR" );
PathBuf::from( manifest_dir ).join( "examples" )
}
#[ test ]
fn example_documentation_no_placeholders()
{
let example_path = examples_dir().join( "wtools_trivial.rs" );
let content = fs::read_to_string( &example_path )
.expect( "Failed to read example file" );
assert!(
!content.contains( "qqq:" ),
"Example contains 'qqq:' placeholder marker at {}: {}",
example_path.display(),
content.lines().find( |line| line.contains( "qqq:" ) ).unwrap_or( "" )
);
assert!(
!content.contains( "xxx:" ),
"Example contains 'xxx:' placeholder marker"
);
assert!(
!content.contains( "TODO: write" ) && !content.contains( "TODO:write" ),
"Example contains 'TODO: write' placeholder"
);
let first_line = content.lines().next().expect( "File is empty" );
assert!(
first_line.starts_with( "//!" ),
"Example should start with documentation comment"
);
assert!(
first_line.len() > 10,
"Documentation should be meaningful, not just '//!'"
);
}
#[ test ]
fn example_consistent_spacing_around_scope_operator()
{
let example_path = examples_dir().join( "wtools_trivial.rs" );
let content = fs::read_to_string( &example_path )
.expect( "Failed to read example file" );
for ( line_num, line ) in content.lines().enumerate()
{
if line.trim().starts_with( "//" ) || line.trim().starts_with( "//!" )
{
continue;
}
let problematic_patterns = [
" ::", ];
for pattern in &problematic_patterns
{
if line.contains( pattern )
{
if let Some( pos ) = line.find( pattern )
{
let before_pattern = &line[ ..pos ];
let quote_count = before_pattern.matches( '"' ).count();
if quote_count % 2 == 1
{
continue; }
if before_pattern.contains( "//" )
{
continue;
}
panic!(
"Inconsistent spacing at line {}: found '{}' - should not have space before ::\nLine: {}",
line_num + 1,
pattern,
line
);
}
}
}
}
}
#[ test ]
fn example_file_exists()
{
let example_path = examples_dir().join( "wtools_trivial.rs" );
assert!(
example_path.exists(),
"Example file does not exist at {}",
example_path.display()
);
}
#[ test ]
fn example_uses_collection_macros()
{
let example_path = examples_dir().join( "wtools_trivial.rs" );
let content = fs::read_to_string( &example_path )
.expect( "Failed to read example file" );
assert!(
content.contains( "hmap!" ) || content.contains( "hset!" ) || content.contains( "vec!" ),
"Example should demonstrate at least one collection macro (hmap!, hset!, vec!)"
);
assert!(
content.contains( "use wtools::" ) || content.contains( "use wtools ::" ),
"Example should import from wtools crate"
);
}