diff options
Diffstat (limited to 'crates/ide_completion/src/tests')
-rw-r--r-- | crates/ide_completion/src/tests/items.rs | 108 |
1 files changed, 108 insertions, 0 deletions
diff --git a/crates/ide_completion/src/tests/items.rs b/crates/ide_completion/src/tests/items.rs new file mode 100644 index 000000000..dd4ba3864 --- /dev/null +++ b/crates/ide_completion/src/tests/items.rs | |||
@@ -0,0 +1,108 @@ | |||
1 | //! Completions tests for item specifics overall. | ||
2 | //! | ||
3 | //! Except for use items which are tested in [super::use_tree] and mod declarations with are tested | ||
4 | //! in [crate::completions::mod_]. | ||
5 | use expect_test::{expect, Expect}; | ||
6 | |||
7 | use crate::tests::completion_list; | ||
8 | |||
9 | fn check(ra_fixture: &str, expect: Expect) { | ||
10 | let base = r#"#[rustc_builtin_macro] | ||
11 | pub macro Clone {} | ||
12 | enum Enum { Variant } | ||
13 | struct Struct {} | ||
14 | #[macro_export] | ||
15 | macro_rules! foo {} | ||
16 | mod bar {} | ||
17 | const CONST: () = (); | ||
18 | trait Trait {} | ||
19 | "#; | ||
20 | let actual = completion_list(&format!("{}{}", base, ra_fixture)); | ||
21 | expect.assert_eq(&actual) | ||
22 | } | ||
23 | |||
24 | #[test] | ||
25 | fn target_type_or_trait_in_impl_block() { | ||
26 | // FIXME: should not complete `Self` | ||
27 | check( | ||
28 | r#" | ||
29 | impl My$0 | ||
30 | "#, | ||
31 | expect![[r##" | ||
32 | sp Self | ||
33 | tt Trait | ||
34 | en Enum | ||
35 | st Struct | ||
36 | md bar | ||
37 | ma foo!(…) #[macro_export] macro_rules! foo | ||
38 | ma foo!(…) #[macro_export] macro_rules! foo | ||
39 | bt u32 | ||
40 | bt bool | ||
41 | bt u8 | ||
42 | bt isize | ||
43 | bt u16 | ||
44 | bt u64 | ||
45 | bt u128 | ||
46 | bt f32 | ||
47 | bt i128 | ||
48 | bt i16 | ||
49 | bt str | ||
50 | bt i64 | ||
51 | bt char | ||
52 | bt f64 | ||
53 | bt i32 | ||
54 | bt i8 | ||
55 | bt usize | ||
56 | "##]], | ||
57 | ) | ||
58 | } | ||
59 | |||
60 | #[test] | ||
61 | fn after_trait_name_in_trait_def() { | ||
62 | // FIXME: should only complete `where` | ||
63 | check( | ||
64 | r"trait A $0", | ||
65 | expect![[r##" | ||
66 | kw where | ||
67 | sn tmod (Test module) | ||
68 | sn tfn (Test function) | ||
69 | sn macro_rules | ||
70 | md bar | ||
71 | ma foo!(…) #[macro_export] macro_rules! foo | ||
72 | ma foo!(…) #[macro_export] macro_rules! foo | ||
73 | "##]], | ||
74 | ); | ||
75 | } | ||
76 | |||
77 | #[test] | ||
78 | fn after_trait_or_target_name_in_impl() { | ||
79 | // FIXME: should only complete `for` and `where` | ||
80 | check( | ||
81 | r"impl A $0", | ||
82 | expect![[r##" | ||
83 | kw where | ||
84 | sn tmod (Test module) | ||
85 | sn tfn (Test function) | ||
86 | sn macro_rules | ||
87 | md bar | ||
88 | ma foo!(…) #[macro_export] macro_rules! foo | ||
89 | ma foo!(…) #[macro_export] macro_rules! foo | ||
90 | "##]], | ||
91 | ); | ||
92 | } | ||
93 | |||
94 | #[test] | ||
95 | fn before_record_field() { | ||
96 | check( | ||
97 | r#" | ||
98 | struct Foo { | ||
99 | $0 | ||
100 | pub f: i32, | ||
101 | } | ||
102 | "#, | ||
103 | expect![[r#" | ||
104 | kw pub(crate) | ||
105 | kw pub | ||
106 | "#]], | ||
107 | ) | ||
108 | } | ||