]> git.lizzy.rs Git - rust.git/commitdiff
Lift out base item fixture for ide_completion tests
authorLukas Wirth <lukastw97@gmail.com>
Wed, 23 Jun 2021 16:37:47 +0000 (18:37 +0200)
committerLukas Wirth <lukastw97@gmail.com>
Wed, 23 Jun 2021 16:37:47 +0000 (18:37 +0200)
crates/ide_completion/src/tests.rs
crates/ide_completion/src/tests/item_list.rs
crates/ide_completion/src/tests/items.rs
crates/ide_completion/src/tests/pattern.rs
crates/ide_completion/src/tests/use_tree.rs
crates/ide_completion/src/tests/where_clause.rs [new file with mode: 0644]

index 97298ff27d05e4bdf0ffbf7100a8794f510fc0eb..12008cf59c11be2508bc71dcd8dcacaa59b4e86d 100644 (file)
@@ -9,6 +9,7 @@
 mod items;
 mod pattern;
 mod type_pos;
+mod where_clause;
 
 use std::mem;
 
 
 use crate::{item::CompletionKind, CompletionConfig, CompletionItem};
 
+/// Lots of basic item definitions
+const BASE_FIXTURE: &str = r#"
+enum Enum { TupleV(u32), RecordV { field: u32 }, UnitV }
+use self::Enum::TupleV;
+mod module {}
+
+trait Trait {}
+static STATIC: Unit = Unit;
+const CONST: Unit = Unit;
+struct Record { field: u32 }
+struct Tuple(u32);
+struct Unit
+macro_rules! makro {}
+"#;
+
 pub(crate) const TEST_CONFIG: CompletionConfig = CompletionConfig {
     enable_postfix_completions: true,
     enable_imports_on_the_fly: true,
index 7c124ac370bc0bf1a23506dfe81b1573d0fa33d3..ae71adf8e00af979281c40ac0d830dc556d0a468 100644 (file)
@@ -1,19 +1,9 @@
 use expect_test::{expect, Expect};
 
-use crate::tests::completion_list;
+use crate::tests::{completion_list, BASE_FIXTURE};
 
 fn check(ra_fixture: &str, expect: Expect) {
-    let base = r#"#[rustc_builtin_macro]
-pub macro Clone {}
-enum Enum { Variant }
-struct Struct {}
-#[macro_export]
-macro_rules! foo {}
-mod bar {}
-const CONST: () = ();
-trait Trait {}
-"#;
-    let actual = completion_list(&format!("{}{}", base, ra_fixture));
+    let actual = completion_list(&format!("{}{}", BASE_FIXTURE, ra_fixture));
     expect.assert_eq(&actual)
 }
 
@@ -21,7 +11,7 @@ trait Trait {}
 fn in_mod_item_list() {
     check(
         r#"mod tests { $0 }"#,
-        expect![[r##"
+        expect![[r#"
             kw pub(crate)
             kw pub
             kw unsafe
@@ -40,8 +30,8 @@ fn in_mod_item_list() {
             sn tmod (Test module)
             sn tfn (Test function)
             sn macro_rules
-            ma foo!(…)          #[macro_export] macro_rules! foo
-        "##]],
+            ma makro!(…)        macro_rules! makro
+        "#]],
     )
 }
 
@@ -49,7 +39,7 @@ fn in_mod_item_list() {
 fn in_source_file_item_list() {
     check(
         r#"$0"#,
-        expect![[r##"
+        expect![[r#"
             kw pub(crate)
             kw pub
             kw unsafe
@@ -68,10 +58,9 @@ fn in_source_file_item_list() {
             sn tmod (Test module)
             sn tfn (Test function)
             sn macro_rules
-            md bar
-            ma foo!(…)          #[macro_export] macro_rules! foo
-            ma foo!(…)          #[macro_export] macro_rules! foo
-        "##]],
+            md module
+            ma makro!(…)        macro_rules! makro
+        "#]],
     )
 }
 
@@ -106,7 +95,7 @@ fn in_item_list_after_attr() {
 fn in_qualified_path() {
     check(
         r#"crate::$0"#,
-        expect![[r##"
+        expect![[r#"
             kw pub(crate)
             kw pub
             kw unsafe
@@ -122,9 +111,8 @@ fn in_qualified_path() {
             kw enum
             kw struct
             kw union
-            md bar
-            ma foo!(…)    #[macro_export] macro_rules! foo
-        "##]],
+            md module
+        "#]],
     )
 }
 
@@ -177,17 +165,16 @@ fn after_visibility_unsafe() {
 fn in_impl_assoc_item_list() {
     check(
         r#"impl Struct { $0 }"#,
-        expect![[r##"
+        expect![[r#"
             kw pub(crate)
             kw pub
             kw unsafe
             kw fn
             kw const
             kw type
-            md bar
-            ma foo!(…)    #[macro_export] macro_rules! foo
-            ma foo!(…)    #[macro_export] macro_rules! foo
-        "##]],
+            md module
+            ma makro!(…)  macro_rules! makro
+        "#]],
     )
 }
 
@@ -210,14 +197,13 @@ fn in_impl_assoc_item_list_after_attr() {
 fn in_trait_assoc_item_list() {
     check(
         r"trait Foo { $0 }",
-        expect![[r##"
+        expect![[r#"
             kw unsafe
             kw fn
             kw const
             kw type
-            md bar
-            ma foo!(…) #[macro_export] macro_rules! foo
-            ma foo!(…) #[macro_export] macro_rules! foo
-        "##]],
+            md module
+            ma makro!(…) macro_rules! makro
+        "#]],
     );
 }
index b98baffd6cea47dd60ad7a65ddcb6b32a163cb77..5acfdcc85da0871c360b74066b89407d3a5cfed8 100644 (file)
@@ -4,20 +4,10 @@
 //! in [crate::completions::mod_].
 use expect_test::{expect, Expect};
 
-use crate::tests::completion_list;
+use crate::tests::{completion_list, BASE_FIXTURE};
 
 fn check(ra_fixture: &str, expect: Expect) {
-    let base = r#"#[rustc_builtin_macro]
-pub macro Clone {}
-enum Enum { Variant }
-struct Struct {}
-#[macro_export]
-macro_rules! foo {}
-mod bar {}
-const CONST: () = ();
-trait Trait {}
-"#;
-    let actual = completion_list(&format!("{}{}", base, ra_fixture));
+    let actual = completion_list(&format!("{}{}", BASE_FIXTURE, ra_fixture));
     expect.assert_eq(&actual)
 }
 
@@ -27,15 +17,16 @@ fn target_type_or_trait_in_impl_block() {
         r#"
 impl Tra$0
 "#,
-        expect![[r##"
+        expect![[r#"
             tt Trait
             en Enum
-            st Struct
-            md bar
-            ma foo!(…) #[macro_export] macro_rules! foo
-            ma foo!(…) #[macro_export] macro_rules! foo
+            st Record
+            st Tuple
+            md module
+            st Unit
+            ma makro!(…) macro_rules! makro
             bt u32
-        "##]],
+        "#]],
     )
 }
 
@@ -45,15 +36,16 @@ fn target_type_in_trait_impl_block() {
         r#"
 impl Trait for Str$0
 "#,
-        expect![[r##"
+        expect![[r#"
             tt Trait
             en Enum
-            st Struct
-            md bar
-            ma foo!(…) #[macro_export] macro_rules! foo
-            ma foo!(…) #[macro_export] macro_rules! foo
+            st Record
+            st Tuple
+            md module
+            st Unit
+            ma makro!(…) macro_rules! makro
             bt u32
-        "##]],
+        "#]],
     )
 }
 
index 1ad5ccd97afa61d3b0f9746490e908c378fbaf60..48c2fa9aa28a0f56e5677b9674da5976473b8e75 100644 (file)
@@ -1,7 +1,7 @@
 //! Completions tests for pattern position.
 use expect_test::{expect, Expect};
 
-use crate::tests::completion_list;
+use crate::tests::{completion_list, BASE_FIXTURE};
 
 fn check(ra_fixture: &str, expect: Expect) {
     let actual = completion_list(ra_fixture);
@@ -9,19 +9,7 @@ fn check(ra_fixture: &str, expect: Expect) {
 }
 
 fn check_with(ra_fixture: &str, expect: Expect) {
-    let base = r#"
-enum Enum { TupleV(u32), RecordV { field: u32 }, UnitV }
-use self::Enum::TupleV;
-mod module {}
-
-static STATIC: Unit = Unit;
-const CONST: Unit = Unit;
-struct Record { field: u32 }
-struct Tuple(u32);
-struct Unit
-macro_rules! makro {}
-"#;
-    let actual = completion_list(&format!("{}\n{}", base, ra_fixture));
+    let actual = completion_list(&format!("{}\n{}", BASE_FIXTURE, ra_fixture));
     expect.assert_eq(&actual)
 }
 
@@ -123,9 +111,9 @@ fn foo() {
 "#,
         expect![[r#"
             kw mut
+            en Enum
             bn Record    Record { field$1 }$0
             st Record
-            en Enum
             bn Tuple     Tuple($1)$0
             st Tuple
             md module
index 7e6748cccd21d5280a62f881feab0e39ecdb255e..7ad679f10eab221f8476c0f1e2e15f0b2de89d1b 100644 (file)
@@ -1,3 +1,4 @@
+//! Completions tests for use trees.
 use expect_test::{expect, Expect};
 
 use crate::tests::completion_list;
diff --git a/crates/ide_completion/src/tests/where_clause.rs b/crates/ide_completion/src/tests/where_clause.rs
new file mode 100644 (file)
index 0000000..0395cbf
--- /dev/null
@@ -0,0 +1,12 @@
+//! Completion tests for inside of where clauses.
+//!
+//! The parent of the where clause tends to bleed completions of itself into the where clause so this
+//! has to be thoroughly tested.
+use expect_test::{expect, Expect};
+
+use crate::tests::completion_list;
+
+fn check(ra_fixture: &str, expect: Expect) {
+    let actual = completion_list(ra_fixture);
+    expect.assert_eq(&actual)
+}