test(ui-egui): read tl! literals past test-only imports

This commit is contained in:
aiongg
2026-10-26 21:17:08 +00:00
parent f1d427762b
commit 303d9a0a4d
+9 -1
View File
@@ -496,7 +496,15 @@ pub fn tl_literals() -> std::collections::BTreeSet<String> {
}
} else if name.ends_with(".rs") && name != "lib.rs" && !name.starts_with("tests") {
let text = std::fs::read_to_string(&path).unwrap_or_default();
let code = text.split("#[cfg(test)]").next().unwrap_or("");
// Code up to the first test item; test-only imports (`#[cfg(test)] use …;`) don't end it.
let code = text
.match_indices("#[cfg(test)]")
.find(|&(at, m)| {
let item = text[at + m.len()..].trim_start();
let item = ["pub(crate) ", "pub(super) ", "pub "].iter().find_map(|p| item.strip_prefix(p)).unwrap_or(item);
!item.starts_with("use ")
})
.map_or(text.as_str(), |(at, _)| &text[..at]);
let mut rest = code;
while let Some(at) = rest.find("tl!(\"") {
rest = &rest[at + 5..];