From d38bf1624d335651dc297fdd92672cdb0ee2ef4f Mon Sep 17 00:00:00 2001 From: Mikhail Rakhmanov Date: Fri, 12 Jun 2020 13:06:26 +0200 Subject: Return snapshots to tests --- crates/ra_ide/src/completion/complete_keyword.rs | 52 ++++++++++++++++-------- 1 file changed, 34 insertions(+), 18 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/complete_keyword.rs b/crates/ra_ide/src/completion/complete_keyword.rs index 2e76f8592..feaa438af 100644 --- a/crates/ra_ide/src/completion/complete_keyword.rs +++ b/crates/ra_ide/src/completion/complete_keyword.rs @@ -118,43 +118,59 @@ mod tests { }, CompletionItemKind, }; - use insta::{assert_snapshot, assert_debug_snapshot}; - use rustc_hash::FxHashSet; + use insta::assert_debug_snapshot; fn do_keyword_completion(code: &str) -> Vec { do_completion(code, CompletionKind::Keyword) } - fn assert_completion_keyword(code: &str, keywords: &[(&str, &str)]) { + fn get_completion_text_and_assert_positions(code: &str) -> Vec<(String, String)> { let (position, completion_items) = do_completion_with_position(code, CompletionKind::Keyword); - let mut expected_keywords = FxHashSet::<(String, String)>::default(); - for (key, value) in keywords { - expected_keywords.insert(((*key).to_string(), (*value).to_string())); - } - let mut returned_keywords = FxHashSet::<(String, String)>::default(); - + let mut returned_keywords = Vec::<(String, String)>::new(); + for item in completion_items { - assert!(item.text_edit().len() == 1); + debug_assert!(item.text_edit().len() == 1); assert!(item.kind() == Some(CompletionItemKind::Keyword)); let atom = item.text_edit().iter().next().unwrap().clone(); assert!(atom.delete.start() == position.offset); assert!(atom.delete.end() == position.offset); let pair = (item.label().to_string(), atom.insert); - returned_keywords.insert(pair); + returned_keywords.push(pair); } - let assert_failed_message = format!("Expected keywords: {:#?}\nReceived keywords: {:#?}", expected_keywords, returned_keywords); - debug_assert!(returned_keywords == expected_keywords, assert_failed_message); + returned_keywords.sort(); + returned_keywords } #[test] fn completes_keywords_in_use_stmt_new_approach() { - assert_completion_keyword( - r" - use <|> - ", - &[("crate", "crate::"), ("self", "self"), ("super", "super::")], + assert_debug_snapshot!( + get_completion_text_and_assert_positions(r" + use <|> + "), + @r###" + [ + ( + "crate", + "crate::", + ), + ( + "self", + "self", + ), + ( + "super", + "super::", + ), + ] + "### ); + // assert_completion_keyword( + // r" + // use <|> + // ", + // &[("crate", "crate::"), ("self", "self"), ("super", "super::")], + // ); } #[test] -- cgit v1.2.3