From c9598a4cbfdf4b0d0d993043dca48c1615b63145 Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Sat, 29 May 2021 17:19:49 +0200 Subject: Add some lint completion tests --- .../src/completions/attribute/derive.rs | 38 +++++++++++++--------- .../src/completions/attribute/lint.rs | 33 +++++++++++++++++++ 2 files changed, 55 insertions(+), 16 deletions(-) (limited to 'crates/ide_completion/src/completions/attribute') diff --git a/crates/ide_completion/src/completions/attribute/derive.rs b/crates/ide_completion/src/completions/attribute/derive.rs index 7b0a778a2..634c0cb00 100644 --- a/crates/ide_completion/src/completions/attribute/derive.rs +++ b/crates/ide_completion/src/completions/attribute/derive.rs @@ -45,6 +45,7 @@ pub(super) fn complete_derive( } } } + fn get_derive_names_in_scope(ctx: &CompletionContext) -> FxHashSet { let mut result = FxHashSet::default(); ctx.scope.process_all_names(&mut |name, scope_def| { @@ -89,12 +90,14 @@ mod tests { } #[test] - fn empty_derive_completion() { + fn no_completion_for_incorrect_derive() { + check(r#"#[derive{$0)] struct Test;"#, expect![[]]) + } + + #[test] + fn empty_derive() { check( - r#" -#[derive($0)] -struct Test {} - "#, + r#"#[derive($0)] struct Test;"#, expect![[r#" at Clone at Clone, Copy @@ -110,23 +113,26 @@ struct Test {} } #[test] - fn no_completion_for_incorrect_derive() { + fn derive_with_input() { check( - r#" -#[derive{$0)] -struct Test {} -"#, - expect![[r#""#]], + r#"#[derive(serde::Serialize, PartialEq, $0)] struct Test;"#, + expect![[r#" + at Clone + at Clone, Copy + at Debug + at Default + at Hash + at Eq + at PartialOrd + at Eq, PartialOrd, Ord + "#]], ) } #[test] - fn derive_with_input_completion() { + fn derive_with_input2() { check( - r#" -#[derive(serde::Serialize, PartialEq, $0)] -struct Test {} -"#, + r#"#[derive($0 serde::Serialize, PartialEq)] struct Test;"#, expect![[r#" at Clone at Clone, Copy diff --git a/crates/ide_completion/src/completions/attribute/lint.rs b/crates/ide_completion/src/completions/attribute/lint.rs index 115c6cfe0..403630dce 100644 --- a/crates/ide_completion/src/completions/attribute/lint.rs +++ b/crates/ide_completion/src/completions/attribute/lint.rs @@ -152,3 +152,36 @@ pub(super) const DEFAULT_LINT_COMPLETIONS: &[LintCompletion] = &[ LintCompletion { label: "unconditional_panic", description: r#"operation will cause a panic at runtime"# }, LintCompletion { label: "unknown_crate_types", description: r#"unknown crate type found in `#[crate_type]` directive"# }, ]; + +#[cfg(test)] +mod tests { + + use crate::test_utils::check_edit; + + #[test] + fn check_empty() { + check_edit( + "deprecated", + r#"#[allow($0)] struct Test;"#, + r#"#[allow(deprecated)] struct Test;"#, + ) + } + + #[test] + fn check_with_existing() { + check_edit( + "deprecated", + r#"#[allow(keyword_idents, $0)] struct Test;"#, + r#"#[allow(keyword_idents, deprecated)] struct Test;"#, + ) + } + + #[test] + fn check_qualified() { + check_edit( + "deprecated", + r#"#[allow(keyword_idents, $0)] struct Test;"#, + r#"#[allow(keyword_idents, deprecated)] struct Test;"#, + ) + } +} -- cgit v1.2.3