From f835279b3ae41644e9568187b4468cd9d9e84eca Mon Sep 17 00:00:00 2001 From: Lukas Wirth Date: Mon, 21 Jun 2021 13:48:25 +0200 Subject: Move out completion pattern tests --- crates/ide_completion/src/completions/pattern.rs | 395 ----------------------- 1 file changed, 395 deletions(-) (limited to 'crates/ide_completion/src/completions/pattern.rs') diff --git a/crates/ide_completion/src/completions/pattern.rs b/crates/ide_completion/src/completions/pattern.rs index efe3c957a..bd13a62d7 100644 --- a/crates/ide_completion/src/completions/pattern.rs +++ b/crates/ide_completion/src/completions/pattern.rs @@ -55,398 +55,3 @@ pub(crate) fn complete_pattern(acc: &mut Completions, ctx: &CompletionContext) { } }); } - -#[cfg(test)] -mod tests { - use expect_test::{expect, Expect}; - - use crate::{ - tests::{check_edit, filtered_completion_list}, - CompletionKind, - }; - - fn check(ra_fixture: &str, expect: Expect) { - let actual = filtered_completion_list(ra_fixture, CompletionKind::Reference); - expect.assert_eq(&actual) - } - - fn check_snippet(ra_fixture: &str, expect: Expect) { - let actual = filtered_completion_list(ra_fixture, CompletionKind::Snippet); - expect.assert_eq(&actual) - } - - #[test] - fn completes_enum_variants_and_modules() { - check( - r#" -enum E { X } -use self::E::X; -const Z: E = E::X; -mod m {} - -static FOO: E = E::X; -struct Bar { f: u32 } - -fn foo() { - match E::X { a$0 } -} -"#, - expect![[r#" - en E - ct Z - st Bar - ev X - md m - "#]], - ); - } - - #[test] - fn does_not_complete_non_fn_macros() { - check( - r#" -macro_rules! m { ($e:expr) => { $e } } -enum E { X } - -#[rustc_builtin_macro] -macro Clone {} - -fn foo() { - match E::X { $0 } -} -"#, - expect![[r#" - ev E::X () - en E - ma m!(…) macro_rules! m - "#]], - ); - } - - #[test] - fn completes_in_simple_macro_call() { - check( - r#" -macro_rules! m { ($e:expr) => { $e } } -enum E { X } - -fn foo() { - m!(match E::X { a$0 }) -} -"#, - expect![[r#" - ev E::X () - en E - ma m!(…) macro_rules! m - "#]], - ); - } - - #[test] - fn completes_in_irrefutable_let() { - check( - r#" -enum E { X } -use self::E::X; -const Z: E = E::X; -mod m {} - -static FOO: E = E::X; -struct Bar { f: u32 } - -fn foo() { - let a$0 -} -"#, - expect![[r#" - st Bar - "#]], - ); - } - - #[test] - fn completes_in_param() { - check( - r#" -enum E { X } - -static FOO: E = E::X; -struct Bar { f: u32 } - -fn foo(a$0) { -} -"#, - expect![[r#" - st Bar - "#]], - ); - } - - #[test] - fn completes_pat_in_let() { - check_snippet( - r#" -struct Bar { f: u32 } - -fn foo() { - let a$0 -} -"#, - expect![[r#" - bn Bar Bar { f$1 }$0 - "#]], - ); - } - - #[test] - fn completes_param_pattern() { - check_snippet( - r#" -struct Foo { bar: String, baz: String } -struct Bar(String, String); -struct Baz; -fn outer(a$0) {} -"#, - expect![[r#" - bn Foo Foo { bar$1, baz$2 }: Foo$0 - bn Bar Bar($1, $2): Bar$0 - "#]], - ) - } - - #[test] - fn completes_let_pattern() { - check_snippet( - r#" -struct Foo { bar: String, baz: String } -struct Bar(String, String); -struct Baz; -fn outer() { - let a$0 -} -"#, - expect![[r#" - bn Foo Foo { bar$1, baz$2 }$0 - bn Bar Bar($1, $2)$0 - "#]], - ) - } - - #[test] - fn completes_refutable_pattern() { - check_snippet( - r#" -struct Foo { bar: i32, baz: i32 } -struct Bar(String, String); -struct Baz; -fn outer() { - match () { - a$0 - } -} -"#, - expect![[r#" - bn Foo Foo { bar$1, baz$2 }$0 - bn Bar Bar($1, $2)$0 - "#]], - ) - } - - #[test] - fn omits_private_fields_pat() { - check_snippet( - r#" -mod foo { - pub struct Foo { pub bar: i32, baz: i32 } - pub struct Bar(pub String, String); - pub struct Invisible(String, String); -} -use foo::*; - -fn outer() { - match () { - a$0 - } -} -"#, - expect![[r#" - bn Foo Foo { bar$1, .. }$0 - bn Bar Bar($1, ..)$0 - "#]], - ) - } - - #[test] - fn only_shows_ident_completion() { - check_edit( - "Foo", - r#" -struct Foo(i32); -fn main() { - match Foo(92) { - a$0(92) => (), - } -} -"#, - r#" -struct Foo(i32); -fn main() { - match Foo(92) { - Foo(92) => (), - } -} -"#, - ); - } - - #[test] - fn completes_self_pats() { - check_snippet( - r#" -struct Foo(i32); -impl Foo { - fn foo() { - match () { - a$0 - } - } -} - "#, - expect![[r#" - bn Self Self($1)$0 - bn Foo Foo($1)$0 - "#]], - ) - } - - #[test] - fn completes_qualified_variant() { - check_snippet( - r#" -enum Foo { - Bar { baz: i32 } -} -impl Foo { - fn foo() { - match {Foo::Bar { baz: 0 }} { - B$0 - } - } -} - "#, - expect![[r#" - bn Self::Bar Self::Bar { baz$1 }$0 - bn Foo::Bar Foo::Bar { baz$1 }$0 - "#]], - ) - } - - #[test] - fn completes_enum_variant_matcharm() { - check( - r#" -enum Foo { Bar, Baz, Quux } - -fn main() { - let foo = Foo::Quux; - match foo { Qu$0 } -} -"#, - expect![[r#" - ev Foo::Bar () - ev Foo::Baz () - ev Foo::Quux () - en Foo - "#]], - ) - } - - #[test] - fn completes_enum_variant_matcharm_ref() { - check( - r#" -enum Foo { Bar, Baz, Quux } - -fn main() { - let foo = Foo::Quux; - match &foo { Qu$0 } -} -"#, - expect![[r#" - ev Foo::Bar () - ev Foo::Baz () - ev Foo::Quux () - en Foo - "#]], - ) - } - - #[test] - fn completes_enum_variant_iflet() { - check( - r#" -enum Foo { Bar, Baz, Quux } - -fn main() { - let foo = Foo::Quux; - if let Qu$0 = foo { } -} -"#, - expect![[r#" - ev Foo::Bar () - ev Foo::Baz () - ev Foo::Quux () - en Foo - "#]], - ) - } - - #[test] - fn completes_enum_variant_impl() { - check( - r#" -enum Foo { Bar, Baz, Quux } -impl Foo { - fn foo() { match Foo::Bar { Q$0 } } -} -"#, - expect![[r#" - ev Self::Bar () - ev Self::Baz () - ev Self::Quux () - ev Foo::Bar () - ev Foo::Baz () - ev Foo::Quux () - sp Self - en Foo - "#]], - ) - } - - #[test] - fn completes_in_record_field_pat() { - check_snippet( - r#" -struct Foo { bar: Bar } -struct Bar(u32); -fn outer(Foo { bar: $0 }: Foo) {} -"#, - expect![[r#" - bn Foo Foo { bar$1 }$0 - bn Bar Bar($1)$0 - "#]], - ) - } - - #[test] - fn skips_in_record_field_pat_name() { - check_snippet( - r#" -struct Foo { bar: Bar } -struct Bar(u32); -fn outer(Foo { bar$0 }: Foo) {} -"#, - expect![[r#""#]], - ) - } -} -- cgit v1.2.3