|
| 1 | +mod regular { |
| 2 | + mod ok { |
| 3 | + #[divan::bench] |
| 4 | + fn en(bencher: divan::Bencher) { |
| 5 | + let input = "finalizes"; |
| 6 | + let locale = typos_cli::config::Locale::En; |
| 7 | + let corrections = typos_cli::dict::BuiltIn::new(locale); |
| 8 | + let input = typos::tokens::Word::new(input, 0).unwrap(); |
| 9 | + #[cfg(feature = "vars")] |
| 10 | + assert_eq!(corrections.correct_word(input), None); |
| 11 | + bencher |
| 12 | + .with_inputs(|| input) |
| 13 | + .bench_local_values(|input| corrections.correct_word(input)); |
| 14 | + } |
| 15 | + |
| 16 | + #[divan::bench] |
| 17 | + #[cfg(feature = "vars")] |
| 18 | + fn en_us(bencher: divan::Bencher) { |
| 19 | + let input = "finalizes"; |
| 20 | + let locale = typos_cli::config::Locale::EnUs; |
| 21 | + let corrections = typos_cli::dict::BuiltIn::new(locale); |
| 22 | + let input = typos::tokens::Word::new(input, 0).unwrap(); |
| 23 | + #[cfg(feature = "vars")] |
| 24 | + assert_eq!(corrections.correct_word(input), Some(typos::Status::Valid)); |
| 25 | + bencher |
| 26 | + .with_inputs(|| input) |
| 27 | + .bench_local_values(|input| corrections.correct_word(input)); |
| 28 | + } |
| 29 | + } |
| 30 | + |
| 31 | + mod misspell { |
| 32 | + #[divan::bench] |
| 33 | + fn en(bencher: divan::Bencher) { |
| 34 | + let input = "finallizes"; |
| 35 | + let output = "finalizes"; |
| 36 | + let locale = typos_cli::config::Locale::En; |
| 37 | + let corrections = typos_cli::dict::BuiltIn::new(locale); |
| 38 | + let input = typos::tokens::Word::new(input, 0).unwrap(); |
| 39 | + assert_eq!( |
| 40 | + corrections.correct_word(input), |
| 41 | + Some(typos::Status::Corrections(vec![ |
| 42 | + std::borrow::Cow::Borrowed(output) |
| 43 | + ])) |
| 44 | + ); |
| 45 | + bencher |
| 46 | + .with_inputs(|| input) |
| 47 | + .bench_local_values(|input| corrections.correct_word(input)); |
| 48 | + } |
| 49 | + |
| 50 | + #[divan::bench] |
| 51 | + #[cfg(feature = "vars")] |
| 52 | + fn en_us(bencher: divan::Bencher) { |
| 53 | + let input = "finallizes"; |
| 54 | + let output = "finalizes"; |
| 55 | + let locale = typos_cli::config::Locale::EnUs; |
| 56 | + let corrections = typos_cli::dict::BuiltIn::new(locale); |
| 57 | + let input = typos::tokens::Word::new(input, 0).unwrap(); |
| 58 | + assert_eq!( |
| 59 | + corrections.correct_word(input), |
| 60 | + Some(typos::Status::Corrections(vec![ |
| 61 | + std::borrow::Cow::Borrowed(output) |
| 62 | + ])) |
| 63 | + ); |
| 64 | + bencher |
| 65 | + .with_inputs(|| input) |
| 66 | + .bench_local_values(|input| corrections.correct_word(input)); |
| 67 | + } |
| 68 | + } |
| 69 | + |
| 70 | + mod misspell_case { |
| 71 | + #[divan::bench] |
| 72 | + fn en(bencher: divan::Bencher) { |
| 73 | + let input = "FINALLIZES"; |
| 74 | + let output = "FINALIZES"; |
| 75 | + let locale = typos_cli::config::Locale::En; |
| 76 | + let corrections = typos_cli::dict::BuiltIn::new(locale); |
| 77 | + let input = typos::tokens::Word::new(input, 0).unwrap(); |
| 78 | + assert_eq!( |
| 79 | + corrections.correct_word(input), |
| 80 | + Some(typos::Status::Corrections(vec![ |
| 81 | + std::borrow::Cow::Borrowed(output) |
| 82 | + ])) |
| 83 | + ); |
| 84 | + bencher |
| 85 | + .with_inputs(|| input) |
| 86 | + .bench_local_values(|input| corrections.correct_word(input)); |
| 87 | + } |
| 88 | + |
| 89 | + #[divan::bench] |
| 90 | + #[cfg(feature = "vars")] |
| 91 | + fn en_us(bencher: divan::Bencher) { |
| 92 | + let input = "FINALLIZES"; |
| 93 | + let output = "FINALIZES"; |
| 94 | + let locale = typos_cli::config::Locale::EnUs; |
| 95 | + let corrections = typos_cli::dict::BuiltIn::new(locale); |
| 96 | + let input = typos::tokens::Word::new(input, 0).unwrap(); |
| 97 | + assert_eq!( |
| 98 | + corrections.correct_word(input), |
| 99 | + Some(typos::Status::Corrections(vec![ |
| 100 | + std::borrow::Cow::Borrowed(output) |
| 101 | + ])) |
| 102 | + ); |
| 103 | + bencher |
| 104 | + .with_inputs(|| input) |
| 105 | + .bench_local_values(|input| corrections.correct_word(input)); |
| 106 | + } |
| 107 | + } |
| 108 | +} |
| 109 | + |
| 110 | +#[cfg(feature = "vars")] |
| 111 | +mod varcon { |
| 112 | + mod ok { |
| 113 | + #[divan::bench] |
| 114 | + fn en_gb(bencher: divan::Bencher) { |
| 115 | + let input = "finalizes"; |
| 116 | + let output = "finalises"; |
| 117 | + let locale = typos_cli::config::Locale::EnGb; |
| 118 | + let corrections = typos_cli::dict::BuiltIn::new(locale); |
| 119 | + let input = typos::tokens::Word::new(input, 0).unwrap(); |
| 120 | + assert_eq!( |
| 121 | + corrections.correct_word(input), |
| 122 | + Some(typos::Status::Corrections(vec![ |
| 123 | + std::borrow::Cow::Borrowed(output) |
| 124 | + ])) |
| 125 | + ); |
| 126 | + bencher |
| 127 | + .with_inputs(|| input) |
| 128 | + .bench_local_values(|input| corrections.correct_word(input)); |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | + mod misspell { |
| 133 | + #[divan::bench] |
| 134 | + fn en_gb(bencher: divan::Bencher) { |
| 135 | + let input = "finallizes"; |
| 136 | + let output = "finalises"; |
| 137 | + let locale = typos_cli::config::Locale::EnGb; |
| 138 | + let corrections = typos_cli::dict::BuiltIn::new(locale); |
| 139 | + let input = typos::tokens::Word::new(input, 0).unwrap(); |
| 140 | + assert_eq!( |
| 141 | + corrections.correct_word(input), |
| 142 | + Some(typos::Status::Corrections(vec![ |
| 143 | + std::borrow::Cow::Borrowed(output) |
| 144 | + ])) |
| 145 | + ); |
| 146 | + bencher |
| 147 | + .with_inputs(|| input) |
| 148 | + .bench_local_values(|input| corrections.correct_word(input)); |
| 149 | + } |
| 150 | + } |
| 151 | +} |
| 152 | + |
| 153 | +fn main() { |
| 154 | + divan::main(); |
| 155 | +} |
0 commit comments