From 828e59ae714556b23a96ff876a7cb57c347d147c Mon Sep 17 00:00:00 2001 From: Simon Gardling Date: Wed, 18 May 2022 08:39:54 -0400 Subject: [PATCH] sort autocomplete hashmap --- parsing/src/autocomplete_hashmap.rs | 9 +++++++++ tests/parsing.rs | 18 +++++++++--------- 2 files changed, 18 insertions(+), 9 deletions(-) diff --git a/parsing/src/autocomplete_hashmap.rs b/parsing/src/autocomplete_hashmap.rs index 83bfe7e..734abaa 100644 --- a/parsing/src/autocomplete_hashmap.rs +++ b/parsing/src/autocomplete_hashmap.rs @@ -47,6 +47,15 @@ pub fn compile_hashmap(data: Vec) -> Vec<(String, String)> { 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 } diff --git a/tests/parsing.rs b/tests/parsing.rs index 42b3734..d888fd1 100644 --- a/tests/parsing.rs +++ b/tests/parsing.rs @@ -5,15 +5,15 @@ use std::collections::HashMap; fn hashmap_gen_test() { let data = vec!["time", "text", "test"]; let expect = vec![ - ("t", r#"Hint::Many(&["ime(", "ext(", "est("])"#), - ("ti", r#"Hint::Single("me(")"#), - ("tim", r#"Hint::Single("e(")"#), - ("time", r#"Hint::Single("(")"#), - ("te", r#"Hint::Many(&["xt(", "st("])"#), - ("tex", r#"Hint::Single("t(")"#), - ("text", r#"Hint::Single("(")"#), - ("tes", r#"Hint::Single("t(")"#), - ("test", r#"Hint::Single("(")"#), + ("t", "Hint::Many(&[\"ime(\", \"ext(\", \"est(\"])"), + ("te", "Hint::Many(&[\"xt(\", \"st(\"])"), + ("tes", "Hint::Single(\"t(\")"), + ("test", "Hint::Single(\"(\")"), + ("tex", "Hint::Single(\"t(\")"), + ("text", "Hint::Single(\"(\")"), + ("ti", "Hint::Single(\"me(\")"), + ("tim", "Hint::Single(\"e(\")"), + ("time", "Hint::Single(\"(\")"), ]; assert_eq!(