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,
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)
}
fn in_mod_item_list() {
check(
r#"mod tests { $0 }"#,
- expect![[r##"
+ expect![[r#"
kw pub(crate)
kw pub
kw unsafe
sn tmod (Test module)
sn tfn (Test function)
sn macro_rules
- ma foo!(…) #[macro_export] macro_rules! foo
- "##]],
+ ma makro!(…) macro_rules! makro
+ "#]],
)
}
fn in_source_file_item_list() {
check(
r#"$0"#,
- expect![[r##"
+ expect![[r#"
kw pub(crate)
kw pub
kw unsafe
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
+ "#]],
)
}
fn in_qualified_path() {
check(
r#"crate::$0"#,
- expect![[r##"
+ expect![[r#"
kw pub(crate)
kw pub
kw unsafe
kw enum
kw struct
kw union
- md bar
- ma foo!(…) #[macro_export] macro_rules! foo
- "##]],
+ md module
+ "#]],
)
}
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
+ "#]],
)
}
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
+ "#]],
);
}
//! 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)
}
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
- "##]],
+ "#]],
)
}
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
- "##]],
+ "#]],
)
}
//! 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);
}
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)
}
"#,
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
+//! Completions tests for use trees.
use expect_test::{expect, Expect};
use crate::tests::completion_list;
--- /dev/null
+//! 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)
+}