mirror of
https://github.com/crate-ci/typos.git
synced 2024-11-22 17:11:07 -05:00
fix(dict): Correctly connect dict with varcon
We had a bug where `finallizes` with EnGb would not correct to `finalises`
This commit is contained in:
parent
77cfccb392
commit
04e55e4e85
1 changed files with 77 additions and 2 deletions
79
src/dict.rs
79
src/dict.rs
|
@ -35,8 +35,14 @@ impl BuiltIn {
|
||||||
|
|
||||||
let word = word_token.token();
|
let word = word_token.token();
|
||||||
let mut corrections = if let Some(correction) = self.correct_with_dict(word) {
|
let mut corrections = if let Some(correction) = self.correct_with_dict(word) {
|
||||||
self.correct_with_vars(word)
|
match self.correct_with_vars(correction) {
|
||||||
.unwrap_or_else(|| Status::Corrections(vec![Cow::Borrowed(correction)]))
|
Some(Status::Valid) => Status::Corrections(vec![Cow::Borrowed(correction)]),
|
||||||
|
Some(correction @ Status::Corrections(_)) => correction,
|
||||||
|
Some(Status::Invalid) => {
|
||||||
|
unreachable!("correct_with_vars should always have valid suggestions")
|
||||||
|
}
|
||||||
|
None => Status::Corrections(vec![Cow::Borrowed(correction)]),
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
self.correct_with_vars(word)?
|
self.correct_with_vars(word)?
|
||||||
};
|
};
|
||||||
|
@ -244,6 +250,75 @@ impl<'i, 'w, D: typos::Dictionary> typos::Dictionary for Override<'i, 'w, D> {
|
||||||
mod test {
|
mod test {
|
||||||
use super::*;
|
use super::*;
|
||||||
|
|
||||||
|
#[cfg(feature = "dict")]
|
||||||
|
#[test]
|
||||||
|
fn test_dict_correct() {
|
||||||
|
let dict = BuiltIn::new(crate::config::Locale::default());
|
||||||
|
let correction = dict.correct_word(typos::tokens::Word::new_unchecked(
|
||||||
|
"finallizes",
|
||||||
|
typos::tokens::Case::Lower,
|
||||||
|
0,
|
||||||
|
));
|
||||||
|
assert_eq!(
|
||||||
|
correction,
|
||||||
|
Some(Status::Corrections(vec!["finalizes".into()]))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "vars")]
|
||||||
|
#[test]
|
||||||
|
fn test_varcon_no_locale() {
|
||||||
|
let dict = BuiltIn::new(crate::config::Locale::En);
|
||||||
|
let correction = dict.correct_word(typos::tokens::Word::new_unchecked(
|
||||||
|
"finalizes",
|
||||||
|
typos::tokens::Case::Lower,
|
||||||
|
0,
|
||||||
|
));
|
||||||
|
assert_eq!(correction, Some(Status::Valid));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "vars")]
|
||||||
|
#[test]
|
||||||
|
fn test_varcon_same_locale() {
|
||||||
|
let dict = BuiltIn::new(crate::config::Locale::EnUs);
|
||||||
|
let correction = dict.correct_word(typos::tokens::Word::new_unchecked(
|
||||||
|
"finalizes",
|
||||||
|
typos::tokens::Case::Lower,
|
||||||
|
0,
|
||||||
|
));
|
||||||
|
assert_eq!(correction, Some(Status::Valid));
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "vars")]
|
||||||
|
#[test]
|
||||||
|
fn test_varcon_different_locale() {
|
||||||
|
let dict = BuiltIn::new(crate::config::Locale::EnGb);
|
||||||
|
let correction = dict.correct_word(typos::tokens::Word::new_unchecked(
|
||||||
|
"finalizes",
|
||||||
|
typos::tokens::Case::Lower,
|
||||||
|
0,
|
||||||
|
));
|
||||||
|
assert_eq!(
|
||||||
|
correction,
|
||||||
|
Some(Status::Corrections(vec!["finalises".into()]))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(all(feature = "dict", feature = "vars"))]
|
||||||
|
#[test]
|
||||||
|
fn test_dict_to_varcon() {
|
||||||
|
let dict = BuiltIn::new(crate::config::Locale::EnGb);
|
||||||
|
let correction = dict.correct_word(typos::tokens::Word::new_unchecked(
|
||||||
|
"finallizes",
|
||||||
|
typos::tokens::Case::Lower,
|
||||||
|
0,
|
||||||
|
));
|
||||||
|
assert_eq!(
|
||||||
|
correction,
|
||||||
|
Some(Status::Corrections(vec!["finalises".into()]))
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_case_correct() {
|
fn test_case_correct() {
|
||||||
let cases = [
|
let cases = [
|
||||||
|
|
Loading…
Reference in a new issue