mirror of
https://github.com/storytold/vectorcraft.git
synced 2026-11-19 02:03:02 +00:00
Command Palette: the catalog check reports a word two search rows add to different groups
A catalog's search rows are now checked together: a word that two rows add to different groups fails the i18n test, naming the word and both groups. A word repeated for one group, and a catalog with no search rows, still pass.
This commit is contained in:
@@ -805,16 +805,15 @@ 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 a catalog add one word to different groups. 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) {
|
||||
bad.extend(crate::palette::words::row_problems(src, tr).into_iter().map(|p| format!("{}: {p}", l.code)));
|
||||
}
|
||||
let rows = entries.iter().filter(|(ctx, _, _)| ctx == crate::palette::words::CONTEXT).map(|(_, src, tr)| (src.as_str(), tr.as_str()));
|
||||
bad.extend(crate::palette::words::catalog_problems(rows).into_iter().map(|p| format!("{}: {p}", l.code)));
|
||||
}
|
||||
assert!(bad.is_empty(), "{bad:#?}");
|
||||
}
|
||||
|
||||
@@ -91,6 +91,27 @@ pub(crate) fn row_problems(source: &str, text: &str) -> Vec<String> {
|
||||
problems
|
||||
}
|
||||
|
||||
/// What is wrong with one catalog's `search` rows, each a group's `source` and its translation
|
||||
/// `text`: each row's [`row_problems`], and a word that rows add to two different groups.
|
||||
#[cfg(test)]
|
||||
pub(crate) fn catalog_problems<'a>(rows: impl IntoIterator<Item = (&'a str, &'a str)>) -> Vec<String> {
|
||||
let mut problems = vec![];
|
||||
let mut groups: std::collections::HashMap<String, &str> = std::collections::HashMap::new();
|
||||
for (source, text) in rows {
|
||||
problems.extend(row_problems(source, text));
|
||||
for (w, _) in row_words(text).filter(|(_, single)| *single) {
|
||||
match groups.get(w.as_str()) {
|
||||
Some(&first) if first != source => problems.push(format!("{w:?} is a word of {first:?} and {source:?}")),
|
||||
Some(_) => {}
|
||||
None => {
|
||||
groups.insert(w, source);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
problems
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
@@ -122,4 +143,16 @@ 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 catalog's rows fail when they add one word to two groups, and pass when a word is repeated
|
||||
/// for one group or the catalog has no rows.
|
||||
#[test]
|
||||
fn a_word_in_two_groups_of_a_catalog_is_checked() {
|
||||
let (remove, artboard) = ("remove, delete, erase, clear", "artboard, canvas");
|
||||
let problems = catalog_problems([(remove, "retrait"), (artboard, "plan, Retrait")]);
|
||||
assert_eq!(problems.len(), 1, "{problems:?}");
|
||||
assert!(problems.iter().all(|p| p.contains("retrait") && p.contains(remove) && p.contains(artboard)), "{problems:?}");
|
||||
assert!(catalog_problems([(remove, "retrait, retrait"), (remove, "Retrait"), (artboard, "plan")]).is_empty());
|
||||
assert!(catalog_problems([]).is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user