From 314efae29d42d2adae990e70eb4ccbaa141a5a06 Mon Sep 17 00:00:00 2001 From: Aleksey Kladov Date: Fri, 3 Jul 2020 15:46:37 +0200 Subject: Refactor attribut completion tests --- crates/ra_ide/src/completion/complete_attribute.rs | 760 ++++----------------- 1 file changed, 115 insertions(+), 645 deletions(-) (limited to 'crates/ra_ide/src/completion') diff --git a/crates/ra_ide/src/completion/complete_attribute.rs b/crates/ra_ide/src/completion/complete_attribute.rs index 4e50a294f..9db317509 100644 --- a/crates/ra_ide/src/completion/complete_attribute.rs +++ b/crates/ra_ide/src/completion/complete_attribute.rs @@ -226,677 +226,147 @@ const DEFAULT_DERIVE_COMPLETIONS: &[DeriveCompletion] = &[ #[cfg(test)] mod tests { - use crate::completion::{test_utils::do_completion, CompletionItem, CompletionKind}; - use insta::assert_debug_snapshot; + use expect::{expect, Expect}; - fn do_attr_completion(code: &str) -> Vec { - do_completion(code, CompletionKind::Attribute) + use crate::completion::{test_utils::completion_list, CompletionKind}; + + fn check(ra_fixture: &str, expect: Expect) { + let actual = completion_list(ra_fixture, CompletionKind::Attribute); + expect.assert_eq(&actual); } #[test] fn empty_derive_completion() { - assert_debug_snapshot!( - do_attr_completion( - r" - #[derive(<|>)] - struct Test {} - ", - ), - @r###" - [ - CompletionItem { - label: "Clone", - source_range: 9..9, - delete: 9..9, - insert: "Clone", - kind: Attribute, - }, - CompletionItem { - label: "Copy, Clone", - source_range: 9..9, - delete: 9..9, - insert: "Copy, Clone", - kind: Attribute, - }, - CompletionItem { - label: "Debug", - source_range: 9..9, - delete: 9..9, - insert: "Debug", - kind: Attribute, - }, - CompletionItem { - label: "Default", - source_range: 9..9, - delete: 9..9, - insert: "Default", - kind: Attribute, - }, - CompletionItem { - label: "Eq, PartialEq", - source_range: 9..9, - delete: 9..9, - insert: "Eq, PartialEq", - kind: Attribute, - }, - CompletionItem { - label: "Hash", - source_range: 9..9, - delete: 9..9, - insert: "Hash", - kind: Attribute, - }, - CompletionItem { - label: "Ord, PartialOrd, Eq, PartialEq", - source_range: 9..9, - delete: 9..9, - insert: "Ord, PartialOrd, Eq, PartialEq", - kind: Attribute, - }, - CompletionItem { - label: "PartialEq", - source_range: 9..9, - delete: 9..9, - insert: "PartialEq", - kind: Attribute, - }, - CompletionItem { - label: "PartialOrd, PartialEq", - source_range: 9..9, - delete: 9..9, - insert: "PartialOrd, PartialEq", - kind: Attribute, - }, - ] - "### + check( + r#" +#[derive(<|>)] +struct Test {} + "#, + expect![[r#" + at Clone + at Copy, Clone + at Debug + at Default + at Eq, PartialEq + at Hash + at Ord, PartialOrd, Eq, PartialEq + at PartialEq + at PartialOrd, PartialEq + "#]], ); } #[test] fn no_completion_for_incorrect_derive() { - assert_debug_snapshot!( - do_attr_completion( - r" - #[derive{<|>)] - struct Test {} - ", - ), - @"[]" - ); + check( + r#" +#[derive{<|>)] +struct Test {} +"#, + expect![[r#""#]], + ) } #[test] fn derive_with_input_completion() { - assert_debug_snapshot!( - do_attr_completion( - r" - #[derive(serde::Serialize, PartialEq, <|>)] - struct Test {} - ", - ), - @r###" - [ - CompletionItem { - label: "Clone", - source_range: 38..38, - delete: 38..38, - insert: "Clone", - kind: Attribute, - }, - CompletionItem { - label: "Copy, Clone", - source_range: 38..38, - delete: 38..38, - insert: "Copy, Clone", - kind: Attribute, - }, - CompletionItem { - label: "Debug", - source_range: 38..38, - delete: 38..38, - insert: "Debug", - kind: Attribute, - }, - CompletionItem { - label: "Default", - source_range: 38..38, - delete: 38..38, - insert: "Default", - kind: Attribute, - }, - CompletionItem { - label: "Eq", - source_range: 38..38, - delete: 38..38, - insert: "Eq", - kind: Attribute, - }, - CompletionItem { - label: "Hash", - source_range: 38..38, - delete: 38..38, - insert: "Hash", - kind: Attribute, - }, - CompletionItem { - label: "Ord, PartialOrd, Eq", - source_range: 38..38, - delete: 38..38, - insert: "Ord, PartialOrd, Eq", - kind: Attribute, - }, - CompletionItem { - label: "PartialOrd", - source_range: 38..38, - delete: 38..38, - insert: "PartialOrd", - kind: Attribute, - }, - ] - "### - ); + check( + r#" +#[derive(serde::Serialize, PartialEq, <|>)] +struct Test {} +"#, + expect![[r#" + at Clone + at Copy, Clone + at Debug + at Default + at Eq + at Hash + at Ord, PartialOrd, Eq + at PartialOrd + "#]], + ) } #[test] fn test_attribute_completion() { - assert_debug_snapshot!( - do_attr_completion( - r" - #[<|>] - ", - ), - @r###" - [ - CompletionItem { - label: "allow(…)", - source_range: 2..2, - delete: 2..2, - insert: "allow(${0:lint})", - kind: Attribute, - lookup: "allow", - }, - CompletionItem { - label: "cfg(…)", - source_range: 2..2, - delete: 2..2, - insert: "cfg(${0:predicate})", - kind: Attribute, - lookup: "cfg", - }, - CompletionItem { - label: "cfg_attr(…)", - source_range: 2..2, - delete: 2..2, - insert: "cfg_attr(${1:predicate}, ${0:attr})", - kind: Attribute, - lookup: "cfg_attr", - }, - CompletionItem { - label: "deny(…)", - source_range: 2..2, - delete: 2..2, - insert: "deny(${0:lint})", - kind: Attribute, - lookup: "deny", - }, - CompletionItem { - label: "deprecated = \"…\"", - source_range: 2..2, - delete: 2..2, - insert: "deprecated = \"${0:reason}\"", - kind: Attribute, - lookup: "deprecated", - }, - CompletionItem { - label: "derive(…)", - source_range: 2..2, - delete: 2..2, - insert: "derive(${0:Debug})", - kind: Attribute, - lookup: "derive", - }, - CompletionItem { - label: "doc = \"…\"", - source_range: 2..2, - delete: 2..2, - insert: "doc = \"${0:docs}\"", - kind: Attribute, - lookup: "doc", - }, - CompletionItem { - label: "forbid(…)", - source_range: 2..2, - delete: 2..2, - insert: "forbid(${0:lint})", - kind: Attribute, - lookup: "forbid", - }, - CompletionItem { - label: "ignore(…)", - source_range: 2..2, - delete: 2..2, - insert: "ignore(${0:lint})", - kind: Attribute, - lookup: "ignore", - }, - CompletionItem { - label: "inline(…)", - source_range: 2..2, - delete: 2..2, - insert: "inline(${0:lint})", - kind: Attribute, - lookup: "inline", - }, - CompletionItem { - label: "link", - source_range: 2..2, - delete: 2..2, - insert: "link", - kind: Attribute, - }, - CompletionItem { - label: "link_name = \"…\"", - source_range: 2..2, - delete: 2..2, - insert: "link_name = \"${0:symbol_name}\"", - kind: Attribute, - lookup: "link_name", - }, - CompletionItem { - label: "macro_export", - source_range: 2..2, - delete: 2..2, - insert: "macro_export", - kind: Attribute, - }, - CompletionItem { - label: "macro_use", - source_range: 2..2, - delete: 2..2, - insert: "macro_use", - kind: Attribute, - }, - CompletionItem { - label: "must_use = \"…\"", - source_range: 2..2, - delete: 2..2, - insert: "must_use = \"${0:reason}\"", - kind: Attribute, - lookup: "must_use", - }, - CompletionItem { - label: "no_mangle", - source_range: 2..2, - delete: 2..2, - insert: "no_mangle", - kind: Attribute, - }, - CompletionItem { - label: "non_exhaustive", - source_range: 2..2, - delete: 2..2, - insert: "non_exhaustive", - kind: Attribute, - }, - CompletionItem { - label: "path = \"…\"", - source_range: 2..2, - delete: 2..2, - insert: "path =\"${0:path}\"", - kind: Attribute, - lookup: "path", - }, - CompletionItem { - label: "proc_macro", - source_range: 2..2, - delete: 2..2, - insert: "proc_macro", - kind: Attribute, - }, - CompletionItem { - label: "proc_macro_attribute", - source_range: 2..2, - delete: 2..2, - insert: "proc_macro_attribute", - kind: Attribute, - }, - CompletionItem { - label: "proc_macro_derive(…)", - source_range: 2..2, - delete: 2..2, - insert: "proc_macro_derive(${0:Trait})", - kind: Attribute, - lookup: "proc_macro_derive", - }, - CompletionItem { - label: "repr(…)", - source_range: 2..2, - delete: 2..2, - insert: "repr(${0:C})", - kind: Attribute, - lookup: "repr", - }, - CompletionItem { - label: "should_panic(…)", - source_range: 2..2, - delete: 2..2, - insert: "should_panic(expected = \"${0:reason}\")", - kind: Attribute, - lookup: "should_panic", - }, - CompletionItem { - label: "target_feature = \"…\"", - source_range: 2..2, - delete: 2..2, - insert: "target_feature = \"${0:feature}\"", - kind: Attribute, - lookup: "target_feature", - }, - CompletionItem { - label: "test", - source_range: 2..2, - delete: 2..2, - insert: "test", - kind: Attribute, - }, - CompletionItem { - label: "used", - source_range: 2..2, - delete: 2..2, - insert: "used", - kind: Attribute, - }, - CompletionItem { - label: "warn(…)", - source_range: 2..2, - delete: 2..2, - insert: "warn(${0:lint})", - kind: Attribute, - lookup: "warn", - }, - ] - "### - ); + check( + r#"#[<|>]"#, + expect![[r#" + at allow(…) + at cfg(…) + at cfg_attr(…) + at deny(…) + at deprecated = "…" + at derive(…) + at doc = "…" + at forbid(…) + at ignore(…) + at inline(…) + at link + at link_name = "…" + at macro_export + at macro_use + at must_use = "…" + at no_mangle + at non_exhaustive + at path = "…" + at proc_macro + at proc_macro_attribute + at proc_macro_derive(…) + at repr(…) + at should_panic(…) + at target_feature = "…" + at test + at used + at warn(…) + "#]], + ) } #[test] fn test_attribute_completion_inside_nested_attr() { - assert_debug_snapshot!( - do_attr_completion( - r" - #[allow(<|>)] - ", - ), - @r###" - [] - "### - ); + check(r#"#[allow(<|>)]"#, expect![[]]) } #[test] fn test_inner_attribute_completion() { - assert_debug_snapshot!( - do_attr_completion( - r" - #![<|>] - ", - ), - @r###" - [ - CompletionItem { - label: "allow(…)", - source_range: 3..3, - delete: 3..3, - insert: "allow(${0:lint})", - kind: Attribute, - lookup: "allow", - }, - CompletionItem { - label: "cfg(…)", - source_range: 3..3, - delete: 3..3, - insert: "cfg(${0:predicate})", - kind: Attribute, - lookup: "cfg", - }, - CompletionItem { - label: "cfg_attr(…)", - source_range: 3..3, - delete: 3..3, - insert: "cfg_attr(${1:predicate}, ${0:attr})", - kind: Attribute, - lookup: "cfg_attr", - }, - CompletionItem { - label: "deny(…)", - source_range: 3..3, - delete: 3..3, - insert: "deny(${0:lint})", - kind: Attribute, - lookup: "deny", - }, - CompletionItem { - label: "deprecated = \"…\"", - source_range: 3..3, - delete: 3..3, - insert: "deprecated = \"${0:reason}\"", - kind: Attribute, - lookup: "deprecated", - }, - CompletionItem { - label: "derive(…)", - source_range: 3..3, - delete: 3..3, - insert: "derive(${0:Debug})", - kind: Attribute, - lookup: "derive", - }, - CompletionItem { - label: "doc = \"…\"", - source_range: 3..3, - delete: 3..3, - insert: "doc = \"${0:docs}\"", - kind: Attribute, - lookup: "doc", - }, - CompletionItem { - label: "feature(…)", - source_range: 3..3, - delete: 3..3, - insert: "feature(${0:flag})", - kind: Attribute, - lookup: "feature", - }, - CompletionItem { - label: "forbid(…)", - source_range: 3..3, - delete: 3..3, - insert: "forbid(${0:lint})", - kind: Attribute, - lookup: "forbid", - }, - CompletionItem { - label: "global_allocator", - source_range: 3..3, - delete: 3..3, - insert: "global_allocator", - kind: Attribute, - }, - CompletionItem { - label: "ignore(…)", - source_range: 3..3, - delete: 3..3, - insert: "ignore(${0:lint})", - kind: Attribute, - lookup: "ignore", - }, - CompletionItem { - label: "inline(…)", - source_range: 3..3, - delete: 3..3, - insert: "inline(${0:lint})", - kind: Attribute, - lookup: "inline", - }, - CompletionItem { - label: "link", - source_range: 3..3, - delete: 3..3, - insert: "link", - kind: Attribute, - }, - CompletionItem { - label: "link_name = \"…\"", - source_range: 3..3, - delete: 3..3, - insert: "link_name = \"${0:symbol_name}\"", - kind: Attribute, - lookup: "link_name", - }, - CompletionItem { - label: "macro_export", - source_range: 3..3, - delete: 3..3, - insert: "macro_export", - kind: Attribute, - }, - CompletionItem { - label: "macro_use", - source_range: 3..3, - delete: 3..3, - insert: "macro_use", - kind: Attribute, - }, - CompletionItem { - label: "must_use = \"…\"", - source_range: 3..3, - delete: 3..3, - insert: "must_use = \"${0:reason}\"", - kind: Attribute, - lookup: "must_use", - }, - CompletionItem { - label: "no_mangle", - source_range: 3..3, - delete: 3..3, - insert: "no_mangle", - kind: Attribute, - }, - CompletionItem { - label: "no_std", - source_range: 3..3, - delete: 3..3, - insert: "no_std", - kind: Attribute, - }, - CompletionItem { - label: "non_exhaustive", - source_range: 3..3, - delete: 3..3, - insert: "non_exhaustive", - kind: Attribute, - }, - CompletionItem { - label: "panic_handler", - source_range: 3..3, - delete: 3..3, - insert: "panic_handler", - kind: Attribute, - }, - CompletionItem { - label: "path = \"…\"", - source_range: 3..3, - delete: 3..3, - insert: "path =\"${0:path}\"", - kind: Attribute, - lookup: "path", - }, - CompletionItem { - label: "proc_macro", - source_range: 3..3, - delete: 3..3, - insert: "proc_macro", - kind: Attribute, - }, - CompletionItem { - label: "proc_macro_attribute", - source_range: 3..3, - delete: 3..3, - insert: "proc_macro_attribute", - kind: Attribute, - }, - CompletionItem { - label: "proc_macro_derive(…)", - source_range: 3..3, - delete: 3..3, - insert: "proc_macro_derive(${0:Trait})", - kind: Attribute, - lookup: "proc_macro_derive", - }, - CompletionItem { - label: "recursion_limit = …", - source_range: 3..3, - delete: 3..3, - insert: "recursion_limit = ${0:128}", - kind: Attribute, - lookup: "recursion_limit", - }, - CompletionItem { - label: "repr(…)", - source_range: 3..3, - delete: 3..3, - insert: "repr(${0:C})", - kind: Attribute, - lookup: "repr", - }, - CompletionItem { - label: "should_panic(…)", - source_range: 3..3, - delete: 3..3, - insert: "should_panic(expected = \"${0:reason}\")", - kind: Attribute, - lookup: "should_panic", - }, - CompletionItem { - label: "target_feature = \"…\"", - source_range: 3..3, - delete: 3..3, - insert: "target_feature = \"${0:feature}\"", - kind: Attribute, - lookup: "target_feature", - }, - CompletionItem { - label: "test", - source_range: 3..3, - delete: 3..3, - insert: "test", - kind: Attribute, - }, - CompletionItem { - label: "used", - source_range: 3..3, - delete: 3..3, - insert: "used", - kind: Attribute, - }, - CompletionItem { - label: "warn(…)", - source_range: 3..3, - delete: 3..3, - insert: "warn(${0:lint})", - kind: Attribute, - lookup: "warn", - }, - CompletionItem { - label: "windows_subsystem = \"…\"", - source_range: 3..3, - delete: 3..3, - insert: "windows_subsystem = \"${0:subsystem}\"", - kind: Attribute, - lookup: "windows_subsystem", - }, - ] - "### + check( + r"#![<|>]", + expect![[r#" + at allow(…) + at cfg(…) + at cfg_attr(…) + at deny(…) + at deprecated = "…" + at derive(…) + at doc = "…" + at feature(…) + at forbid(…) + at global_allocator + at ignore(…) + at inline(…) + at link + at link_name = "…" + at macro_export + at macro_use + at must_use = "…" + at no_mangle + at no_std + at non_exhaustive + at panic_handler + at path = "…" + at proc_macro + at proc_macro_attribute + at proc_macro_derive(…) + at recursion_limit = … + at repr(…) + at should_panic(…) + at target_feature = "…" + at test + at used + at warn(…) + at windows_subsystem = "…" + "#]], ); } } -- cgit v1.2.3