Skip to content

Commit

Permalink
Expose EN_US fixture crate-wide
Browse files Browse the repository at this point in the history
The checker, lib and suggester all use it for testing. We can use only
one instance by making these constants/statics on the crate instead of
per-module.
  • Loading branch information
the-mikedavis committed Sep 13, 2024
1 parent 17f7b9d commit 9e6908d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
10 changes: 1 addition & 9 deletions src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2287,16 +2287,8 @@ impl<'aff> CompoundingResult<'aff> {

#[cfg(test)]
mod test {
use once_cell::sync::Lazy;

use super::*;

const EN_US_AFF: &str = include_str!("../vendor/en_US/en_US.aff");
const EN_US_DIC: &str = include_str!("../vendor/en_US/en_US.dic");

// It's a little overkill to use a real dictionary for unit tests but it compiles so
// quickly that if we only compile it once it doesn't really slow down the test suite.
static EN_US: Lazy<Dictionary> = Lazy::new(|| Dictionary::new(EN_US_AFF, EN_US_DIC).unwrap());
use crate::EN_US;

#[test]
fn are_three_chars_equal_test() {
Expand Down
14 changes: 10 additions & 4 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,14 +513,20 @@ fn erase_chars<'a>(word: &'a str, ignore: &[char]) -> Cow<'a, str> {
}
}

#[cfg(test)]
const EN_US_AFF: &str = include_str!("../vendor/en_US/en_US.aff");
#[cfg(test)]
const EN_US_DIC: &str = include_str!("../vendor/en_US/en_US.dic");
// It's a little overkill to use a real dictionary for unit tests but it compiles so
// quickly that if we only compile it once it doesn't slow down the test suite.
#[cfg(test)]
static EN_US: once_cell::sync::Lazy<Dictionary> =
once_cell::sync::Lazy::new(|| Dictionary::new(EN_US_AFF, EN_US_DIC).unwrap());

#[cfg(test)]
mod test {
use super::*;

const EN_US_AFF: &str = include_str!("../vendor/en_US/en_US.aff");
const EN_US_DIC: &str = include_str!("../vendor/en_US/en_US.dic");
// static EN_US: Lazy<Dictionary> = Lazy::new(|| Dictionary::new(EN_US_AFF, EN_US_DIC).unwrap());

macro_rules! flag {
( $x:expr ) => {{
Flag::new($x as u16).unwrap()
Expand Down

0 comments on commit 9e6908d

Please sign in to comment.