@@ -35,8 +35,14 @@ impl BuiltIn {
35
35
36
36
let word = word_token. token ( ) ;
37
37
let mut corrections = if let Some ( correction) = self . correct_with_dict ( word) {
38
- self . correct_with_vars ( word)
39
- . unwrap_or_else ( || Status :: Corrections ( vec ! [ Cow :: Borrowed ( correction) ] ) )
38
+ match self . correct_with_vars ( correction) {
39
+ Some ( Status :: Valid ) => Status :: Corrections ( vec ! [ Cow :: Borrowed ( correction) ] ) ,
40
+ Some ( correction @ Status :: Corrections ( _) ) => correction,
41
+ Some ( Status :: Invalid ) => {
42
+ unreachable ! ( "correct_with_vars should always have valid suggestions" )
43
+ }
44
+ None => Status :: Corrections ( vec ! [ Cow :: Borrowed ( correction) ] ) ,
45
+ }
40
46
} else {
41
47
self . correct_with_vars ( word) ?
42
48
} ;
@@ -244,6 +250,75 @@ impl<'i, 'w, D: typos::Dictionary> typos::Dictionary for Override<'i, 'w, D> {
244
250
mod test {
245
251
use super :: * ;
246
252
253
+ #[ cfg( feature = "dict" ) ]
254
+ #[ test]
255
+ fn test_dict_correct ( ) {
256
+ let dict = BuiltIn :: new ( crate :: config:: Locale :: default ( ) ) ;
257
+ let correction = dict. correct_word ( typos:: tokens:: Word :: new_unchecked (
258
+ "finallizes" ,
259
+ typos:: tokens:: Case :: Lower ,
260
+ 0 ,
261
+ ) ) ;
262
+ assert_eq ! (
263
+ correction,
264
+ Some ( Status :: Corrections ( vec![ "finalizes" . into( ) ] ) )
265
+ ) ;
266
+ }
267
+
268
+ #[ cfg( feature = "vars" ) ]
269
+ #[ test]
270
+ fn test_varcon_no_locale ( ) {
271
+ let dict = BuiltIn :: new ( crate :: config:: Locale :: En ) ;
272
+ let correction = dict. correct_word ( typos:: tokens:: Word :: new_unchecked (
273
+ "finalizes" ,
274
+ typos:: tokens:: Case :: Lower ,
275
+ 0 ,
276
+ ) ) ;
277
+ assert_eq ! ( correction, Some ( Status :: Valid ) ) ;
278
+ }
279
+
280
+ #[ cfg( feature = "vars" ) ]
281
+ #[ test]
282
+ fn test_varcon_same_locale ( ) {
283
+ let dict = BuiltIn :: new ( crate :: config:: Locale :: EnUs ) ;
284
+ let correction = dict. correct_word ( typos:: tokens:: Word :: new_unchecked (
285
+ "finalizes" ,
286
+ typos:: tokens:: Case :: Lower ,
287
+ 0 ,
288
+ ) ) ;
289
+ assert_eq ! ( correction, Some ( Status :: Valid ) ) ;
290
+ }
291
+
292
+ #[ cfg( feature = "vars" ) ]
293
+ #[ test]
294
+ fn test_varcon_different_locale ( ) {
295
+ let dict = BuiltIn :: new ( crate :: config:: Locale :: EnGb ) ;
296
+ let correction = dict. correct_word ( typos:: tokens:: Word :: new_unchecked (
297
+ "finalizes" ,
298
+ typos:: tokens:: Case :: Lower ,
299
+ 0 ,
300
+ ) ) ;
301
+ assert_eq ! (
302
+ correction,
303
+ Some ( Status :: Corrections ( vec![ "finalises" . into( ) ] ) )
304
+ ) ;
305
+ }
306
+
307
+ #[ cfg( all( feature = "dict" , feature = "vars" ) ) ]
308
+ #[ test]
309
+ fn test_dict_to_varcon ( ) {
310
+ let dict = BuiltIn :: new ( crate :: config:: Locale :: EnGb ) ;
311
+ let correction = dict. correct_word ( typos:: tokens:: Word :: new_unchecked (
312
+ "finallizes" ,
313
+ typos:: tokens:: Case :: Lower ,
314
+ 0 ,
315
+ ) ) ;
316
+ assert_eq ! (
317
+ correction,
318
+ Some ( Status :: Corrections ( vec![ "finalises" . into( ) ] ) )
319
+ ) ;
320
+ }
321
+
247
322
#[ test]
248
323
fn test_case_correct ( ) {
249
324
let cases = [
0 commit comments