diff --git a/crates/ui-egui/src/i18n/tests.rs b/crates/ui-egui/src/i18n/tests.rs index 8e361ee12..2a44072f0 100644 --- a/crates/ui-egui/src/i18n/tests.rs +++ b/crates/ui-egui/src/i18n/tests.rs @@ -1041,13 +1041,7 @@ fn format_messages() -> std::collections::BTreeSet { 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 { + 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 { // built from parts, so this file's own source holds no call to find