Skip to content

Offline, privacy-first grammar checker. Fast, open-source, Rust-powered

style(fst-dictionary): add comments to document common_words_first test

Grant Lemons41e4120e63f1
diff --git a/Cargo.lock b/Cargo.lock
index 1f837793e..2b9d597ce 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -304,7 +304,6 @@ dependencies = [
"num-traits",
"once_cell",
"oorandom",
- "plotters",
"regex",
"serde",
"serde_derive",
@@ -1162,34 +1161,6 @@ version = "0.1.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184"
-[[package]]
-name = "plotters"
-version = "0.3.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "5aeb6f403d7a4911efb1e33402027fc44f29b5bf6def3effcc22d7bb75f2b747"
-dependencies = [
- "num-traits",
- "plotters-backend",
- "plotters-svg",
- "wasm-bindgen",
- "web-sys",
-]
-
-[[package]]
-name = "plotters-backend"
-version = "0.3.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "df42e13c12958a16b3f7f4386b9ab1f3e7933914ecea48da7139435263a4172a"
-
-[[package]]
-name = "plotters-svg"
-version = "0.3.7"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "51bae2ac328883f7acdfea3d66a7c35751187f870bc81f94563733a154d7a670"
-dependencies = [
- "plotters-backend",
-]
-
[[package]]
name = "ppv-lite86"
version = "0.2.20"
@@ -2003,16 +1974,6 @@ version = "0.2.95"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "65fc09f10666a9f147042251e0dda9c18f166ff7de300607007e96bdebc1068d"
-[[package]]
-name = "web-sys"
-version = "0.3.72"
-source = "registry+https://github.com/rust-lang/crates.io-index"
-checksum = "f6488b90108c040df0fe62fa815cbdee25124641df01814dd7282749234c6112"
-dependencies = [
- "js-sys",
- "wasm-bindgen",
-]
-
[[package]]
name = "winapi"
version = "0.3.9"
diff --git a/harper-core/src/spell/mod.rs b/harper-core/src/spell/mod.rs
index 2a229b0f0..6993f8525 100644
--- a/harper-core/src/spell/mod.rs
+++ b/harper-core/src/spell/mod.rs
@@ -237,9 +237,11 @@ mod tests {
assert_eq!(edit_distance(&source, &target), 1);
}
+ /// Ensures that the suggestions are ordered taking into account commonality
#[test]
fn common_words_first() {
let dict = FstDictionary::curated();
+ // Select three common words
let common_words = dict
.words_iter()
.filter_map(|word| {
@@ -255,6 +257,7 @@ mod tests {
}
})
.take(3);
+ // Select three uncommon words
let uncommon_words = dict
.words_iter()
.filter_map(|word| {
@@ -270,9 +273,12 @@ mod tests {
}
})
.take(3);
- let words = common_words.merge(uncommon_words).collect();
+ // Feed the common and uncommon words into the ordering function, starting with uncommon
+ // words
+ let words = uncommon_words.merge(common_words).collect();
let suggestions = order_suggestions(words);
+ // Asserts that the ordering prioritizes common words
let common_first = suggestions
.into_iter()
.take(3)