use stern4rust::finding::parsing::module_declaration_finder::ModuleDeclarationFinder;
use stern4rust::source_file::SourceFile;
fn found(contents: &str) -> Vec<String> {
ModuleDeclarationFinder::find(&SourceFile::new("src/lib.rs", contents)).expect("parses")
}
#[test]
fn find_of_a_file_that_does_not_parse_returns_nothing() {
let found = ModuleDeclarationFinder::find(&SourceFile::new("src/lib.rs", "pub mod ( broken\n"));
assert!(found.is_none());
}
#[test]
fn find_of_a_private_declaration_counts_it() {
let names = found("mod widget;\n");
assert_eq!(names, ["widget"]);
}
#[test]
fn find_of_a_public_declaration_counts_it() {
let names = found("pub mod widget;\n");
assert_eq!(names, ["widget"]);
}
#[test]
fn find_of_a_registry_with_no_declarations_is_empty() {
let names = found("// just a header\n");
assert!(names.is_empty(), "expected none, got {names:?}");
}
#[test]
fn find_of_an_inline_module_does_not_count_it() {
let names = found("pub mod widget { pub struct W; }\n");
assert!(names.is_empty(), "expected none, got {names:?}");
}
#[test]
fn find_of_several_declarations_keeps_the_order_they_appear_in() {
let names = found("pub mod beta;\npub mod alpha;\n");
assert_eq!(names, ["beta", "alpha"]);
}