Command Palette: a word two search rows of one catalog add is reported

The i18n test of the `search` rows now also checks that no two rows of
one catalog add the same word. Such a word was given to only the first
row's group, so a search for it did not find results through the other
group.
This commit is contained in:
dotCooCoo
2026-11-18 06:16:55 -08:00
parent 53e2b49fb0
commit 8cc6b074b9
2 changed files with 39 additions and 3 deletions
+6 -3
View File
@@ -805,16 +805,19 @@ fn anti_aliasing_method_labels_are_in_complete_catalogs() {
}
/// Each row in the `search` context, which adds a language's words to a group of words with the same
/// meaning for the command palette, names a group and adds single words of no other group. No
/// catalog has to have these rows.
/// meaning for the command palette, names a group and adds single words of no other group, and no
/// two rows of one catalog add the same word. No catalog has to have these rows.
#[test]
fn search_rows_name_a_group_and_add_single_words() {
let mut bad = Vec::new();
for l in LANGUAGES.iter().filter(|l| !l.source.is_empty()) {
let (entries, _) = parse_entries(l.source);
for (_, src, tr) in entries.iter().filter(|(ctx, _, _)| ctx == crate::palette::words::CONTEXT) {
let rows: Vec<(&str, &str)> =
entries.iter().filter(|(ctx, _, _)| ctx == crate::palette::words::CONTEXT).map(|(_, src, tr)| (src.as_str(), tr.as_str())).collect();
for &(src, tr) in &rows {
bad.extend(crate::palette::words::row_problems(src, tr).into_iter().map(|p| format!("{}: {p}", l.code)));
}
bad.extend(crate::palette::words::shared_row_words(&rows).into_iter().map(|p| format!("{}: {p}", l.code)));
}
assert!(bad.is_empty(), "{bad:#?}");
}
+33
View File
@@ -91,6 +91,29 @@ pub(crate) fn row_problems(source: &str, text: &str) -> Vec<String> {
problems
}
/// The words that more than one of a catalog's `search` rows, given as `(source, text)`, add, each
/// with the first two rows that add it.
#[cfg(test)]
pub(crate) fn shared_row_words(rows: &[(&str, &str)]) -> Vec<String> {
let mut first: std::collections::HashMap<String, &str> = std::collections::HashMap::new();
let mut problems = vec![];
for &(source, text) in rows {
for (w, single) in row_words(text) {
if !single {
continue;
}
match first.get(&w) {
Some(&other) if other != source => problems.push(format!("{w:?} is a word of {other:?} and {source:?}")),
Some(_) => {}
None => {
first.insert(w, source);
}
}
}
}
problems
}
#[cfg(test)]
mod tests {
use super::*;
@@ -122,4 +145,14 @@ mod tests {
assert_eq!(row_problems("remove, delete, erase, clear", "ganz entfernen").len(), 1, "two words");
assert_eq!(row_problems("remove, delete, erase, clear", "Text").len(), 1, "a word of another group once lowercased");
}
/// A word that two `search` rows of one catalog add is reported; a word repeated in one row is not.
#[test]
fn a_word_in_two_rows_of_a_catalog_is_reported() {
let remove = "remove, delete, erase, clear";
let image = "image, picture, photo, img, bitmap";
assert!(shared_row_words(&[(remove, "entfernen, löschen"), (image, "bild, foto")]).is_empty());
assert!(shared_row_words(&[(remove, "entfernen, Entfernen")]).is_empty(), "one row");
assert_eq!(shared_row_words(&[(remove, "entfernen, löschen"), (image, "Bild, Löschen")]).len(), 1);
}
}