sort autocomplete hashmap

This commit is contained in:
Simon Gardling 2022-05-18 08:39:54 -04:00
parent 624d50caaf
commit 828e59ae71
2 changed files with 18 additions and 9 deletions

View File

@ -47,6 +47,15 @@ pub fn compile_hashmap(data: Vec<String>) -> Vec<(String, String)> {
panic!("Number of values for {key} is 0!"); panic!("Number of values for {key} is 0!");
} }
} }
// sort
output.sort_unstable_by(|a, b| {
let new_a = format!(r#"("{}", {})"#, a.0, a.1);
let new_b = format!(r#"("{}", {})"#, b.0, b.1);
compare_len_reverse_alpha(&new_b, &new_a)
});
output output
} }

View File

@ -5,15 +5,15 @@ use std::collections::HashMap;
fn hashmap_gen_test() { fn hashmap_gen_test() {
let data = vec!["time", "text", "test"]; let data = vec!["time", "text", "test"];
let expect = vec![ let expect = vec![
("t", r#"Hint::Many(&["ime(", "ext(", "est("])"#), ("t", "Hint::Many(&[\"ime(\", \"ext(\", \"est(\"])"),
("ti", r#"Hint::Single("me(")"#), ("te", "Hint::Many(&[\"xt(\", \"st(\"])"),
("tim", r#"Hint::Single("e(")"#), ("tes", "Hint::Single(\"t(\")"),
("time", r#"Hint::Single("(")"#), ("test", "Hint::Single(\"(\")"),
("te", r#"Hint::Many(&["xt(", "st("])"#), ("tex", "Hint::Single(\"t(\")"),
("tex", r#"Hint::Single("t(")"#), ("text", "Hint::Single(\"(\")"),
("text", r#"Hint::Single("(")"#), ("ti", "Hint::Single(\"me(\")"),
("tes", r#"Hint::Single("t(")"#), ("tim", "Hint::Single(\"e(\")"),
("test", r#"Hint::Single("(")"#), ("time", "Hint::Single(\"(\")"),
]; ];
assert_eq!( assert_eq!(