mirror of
https://github.com/storytold/lightcraft.git
synced 2026-10-28 03:57:57 -06:00
test: the format-message scan skips only inline test modules
This commit is contained in:
@@ -1041,13 +1041,7 @@ fn format_messages() -> std::collections::BTreeSet<String> {
|
||||
dirs.push(path);
|
||||
} else if path.extension().is_some_and(|ext| ext == "rs") {
|
||||
let source = std::fs::read_to_string(&path).unwrap();
|
||||
let app = source
|
||||
.split(
|
||||
"#[cfg(test)]
|
||||
mod ",
|
||||
)
|
||||
.next()
|
||||
.unwrap_or_default();
|
||||
let app = test_module_start(&source).map_or(source.as_str(), |at| &source[..at]);
|
||||
all.extend(tr_format_messages(app));
|
||||
}
|
||||
}
|
||||
@@ -1055,6 +1049,16 @@ mod ",
|
||||
all
|
||||
}
|
||||
|
||||
/// Where the first inline `#[cfg(test)] mod x { … }` starts. A `#[cfg(test)] mod x;` line only
|
||||
/// declares a file, and app code can follow it.
|
||||
fn test_module_start(source: &str) -> Option<usize> {
|
||||
let head = "#[cfg(test)]\nmod ";
|
||||
source
|
||||
.match_indices(head)
|
||||
.map(|(at, _)| at)
|
||||
.find(|at| source[at + head.len()..].trim_start_matches(|c: char| c.is_alphanumeric() || c == '_').starts_with(" {"))
|
||||
}
|
||||
|
||||
/// The first argument of each `tr_format!` call in `source`, when it is a string literal.
|
||||
fn tr_format_messages(source: &str) -> Vec<String> {
|
||||
// built from parts, so this file's own source holds no call to find
|
||||
|
||||
Reference in New Issue
Block a user