CP4.2: review — on 48ed6f8 English without data looks in the dictionaries folder, then an English Language pack, then the system's Hunspell, then the built-in list

hunspell::candidates (which English now loads from) searches the pack tier between the dictionaries folder and the system, as find() does; pack-loaded English goes through the same reloads guard.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01FypgCX8LsYYE8fsj4byBm2
This commit is contained in:
Martin BallandClaude Opus 5.5 committed 2026-11-01 22:34:32 +00:00
1 parent 66d4dd3a5d
commit 664af9bc6f
2 files changed
+37 -4

No files matched your search

+4 -4
View File
@@ -164,10 +164,10 @@ pub fn find(names: &[&str]) -> Option<(PathBuf, PathBuf)> {
.or_else(|| system.iter().find_map(|dir| find_in(dir, names)))
}
/// Every `<name>.aff`/`<name>.dic` pair for `names`, name by name, each in every folder
/// ([`search_dirs`], the dictionaries folder first): a file with the first name in a system
/// folder comes before one with the second name in the dictionaries folder. A caller that can't
/// read one tries the next.
/// Every `<name>.aff`/`<name>.dic` pair for `names`, in the order [`find`] prefers them: the
/// dictionaries folders, then installed Language packs for `names` (their `spelling.aff`/
/// `spelling.dic`), then the system's folders; folder by folder, each folder's in the order of
/// `names`. A caller that can't read one tries the next.
pub fn candidates(names: &[&str]) -> Vec<(PathBuf, PathBuf)> {
let lo = names.first().copied().map(lo_ext_dirs);
candidates_in(&search_dirs(lo.as_deref()), names)
+33
View File
@@ -1226,6 +1226,39 @@ mod tests {
assert_ne!(english_source(ProofLang::En), Some(EnglishSource::Hunspell(dir.join("en_US.dic"))));
}
/// CP4.2: with no embedded word list, English looks in the dictionaries folder, then an
/// installed English Language pack, then the system's Hunspell, then the built-in list.
#[test]
fn an_english_pack_comes_after_the_dictionaries_folder() {
let _guard = DICTIONARY_TESTS.lock().unwrap_or_else(std::sync::PoisonError::into_inner);
set_dictionaries_folder(Some(shared_test_folder()));
let root = std::env::temp_dir().join(format!("wc-proof-en-pack-{}", std::process::id()));
let _ = std::fs::remove_dir_all(&root);
let (dir, packs) = (root.join("dictionaries"), root.join("language-packs"));
let aff: &[u8] = b"SET UTF-8\nSFX S Y 1\nSFX S 0 s .\n";
let pack = write_pack(&packs, "en-us", &[("spelling.aff", aff), ("spelling.dic", b"2\nzzpackword\nhouse/S\n")]);
packs::set_packs_dir(Some(packs.clone()));
let english: &[(&str, &[u8], &[u8])] = &[("en_US", aff, b"2\nzzfolderword\nhouse/S\n")];
folder_with_english(&dir, english);
if english_data() {
assert_eq!(english_source(ProofLang::En), Some(EnglishSource::Embedded));
} else {
assert_eq!(english_source(ProofLang::En), Some(EnglishSource::Hunspell(dir.join("en_US.dic"))), "the folder first");
assert!(is_correct_in("zzfolderword", ProofLang::En) && !is_correct_in("zzpackword", ProofLang::En));
}
drop_english_files(&dir, english);
if !english_data() {
assert_eq!(english_source(ProofLang::En), Some(EnglishSource::Hunspell(pack.join("spelling.dic"))), "then the pack");
assert!(is_correct_in("zzpackword", ProofLang::En) && is_correct_in("houses", ProofLang::En));
}
packs::set_packs_dir(None);
if !english_data() {
assert_ne!(english_source(ProofLang::En), Some(EnglishSource::Hunspell(pack.join("spelling.dic"))), "a removed pack is not used");
}
set_dictionaries_folder(Some(shared_test_folder()));
let _ = std::fs::remove_dir_all(&root);
}
/// R6.4: an English Hunspell dictionary that is there but can't be read (an encoding we don't
/// read, bytes that aren't UTF-8, no words) is an error reported for its English, never a
/// panic, and that English falls back to the next dictionary or the built-in word list, which