aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/nameres/tests
diff options
context:
space:
mode:
authorbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-07-07 14:48:58 +0100
committerbors[bot] <26634292+bors[bot]@users.noreply.github.com>2019-07-07 14:48:58 +0100
commit6c31f5b0a79c8b97110aaf854b839b57811c375a (patch)
treefe355f80c97e9e5fafe787ff0c9d5dd176df2c41 /crates/ra_hir/src/nameres/tests
parent89bfc59f1adc4c41235c4a17048c79c570eff6f4 (diff)
parent1c582be63b35c6602638023d4bd0bc426b0ca744 (diff)
Merge #1499
1499: processing attribute #[path] of module r=matklad a=andreevlex support two cases - simple name file `foo.rs` - declaration in mod.rs #1211 Co-authored-by: Alexander Andreev <[email protected]>
Diffstat (limited to 'crates/ra_hir/src/nameres/tests')
-rw-r--r--crates/ra_hir/src/nameres/tests/mods.rs192
1 files changed, 192 insertions, 0 deletions
diff --git a/crates/ra_hir/src/nameres/tests/mods.rs b/crates/ra_hir/src/nameres/tests/mods.rs
new file mode 100644
index 000000000..7c8c832fc
--- /dev/null
+++ b/crates/ra_hir/src/nameres/tests/mods.rs
@@ -0,0 +1,192 @@
1use super::*;
2
3#[test]
4fn name_res_works_for_broken_modules() {
5 covers!(name_res_works_for_broken_modules);
6 let map = def_map(
7 "
8 //- /lib.rs
9 mod foo // no `;`, no body
10
11 use self::foo::Baz;
12
13 //- /foo/mod.rs
14 pub mod bar;
15
16 pub use self::bar::Baz;
17
18 //- /foo/bar.rs
19 pub struct Baz;
20 ",
21 );
22 assert_snapshot_matches!(map, @r###"
23 ⋮crate
24 ⋮Baz: _
25 "###);
26}
27
28#[test]
29fn module_resolution_works_for_non_standard_filenames() {
30 let map = def_map_with_crate_graph(
31 "
32 //- /my_library.rs
33 mod foo;
34 use self::foo::Bar;
35
36 //- /foo/mod.rs
37 pub struct Bar;
38 ",
39 crate_graph! {
40 "my_library": ("/my_library.rs", []),
41 },
42 );
43
44 assert_snapshot_matches!(map, @r###"
45 ⋮crate
46 ⋮Bar: t v
47 ⋮foo: t
48
49 ⋮crate::foo
50 ⋮Bar: t v
51 "###);
52}
53
54#[test]
55fn module_resolution_works_for_raw_modules() {
56 let map = def_map_with_crate_graph(
57 "
58 //- /library.rs
59 mod r#async;
60 use self::r#async::Bar;
61
62 //- /async.rs
63 pub struct Bar;
64 ",
65 crate_graph! {
66 "library": ("/library.rs", []),
67 },
68 );
69
70 assert_snapshot_matches!(map, @r###"
71 ⋮crate
72 ⋮Bar: t v
73 ⋮async: t
74
75 ⋮crate::async
76 ⋮Bar: t v
77 "###);
78}
79
80#[test]
81fn module_resolution_decl_path() {
82 let map = def_map_with_crate_graph(
83 "
84 //- /library.rs
85 #[path = \"bar/baz/foo.rs\"]
86 mod foo;
87 use self::foo::Bar;
88
89 //- /bar/baz/foo.rs
90 pub struct Bar;
91 ",
92 crate_graph! {
93 "library": ("/library.rs", []),
94 },
95 );
96
97 assert_snapshot_matches!(map, @r###"
98 ⋮crate
99 ⋮Bar: t v
100 ⋮foo: t
101
102 ⋮crate::foo
103 ⋮Bar: t v
104 "###);
105}
106
107#[test]
108fn module_resolution_module_with_path_in_mod_rs() {
109 let map = def_map_with_crate_graph(
110 "
111 //- /main.rs
112 mod foo;
113
114 //- /foo/mod.rs
115 #[path = \"baz.rs\"]
116 pub mod bar;
117
118 use self::bar::Baz;
119
120 //- /foo/baz.rs
121 pub struct Baz;
122 ",
123 crate_graph! {
124 "main": ("/main.rs", []),
125 },
126 );
127
128 assert_snapshot_matches!(map, @r###"
129 ⋮crate
130 ⋮foo: t
131
132 ⋮crate::foo
133 ⋮Baz: t v
134 ⋮bar: t
135
136 ⋮crate::foo::bar
137 ⋮Baz: t v
138 "###);
139}
140
141#[test]
142fn module_resolution_module_with_path_non_crate_root() {
143 let map = def_map_with_crate_graph(
144 "
145 //- /main.rs
146 mod foo;
147
148 //- /foo.rs
149 #[path = \"baz.rs\"]
150 pub mod bar;
151
152 use self::bar::Baz;
153
154 //- /baz.rs
155 pub struct Baz;
156 ",
157 crate_graph! {
158 "main": ("/main.rs", []),
159 },
160 );
161
162 assert_snapshot_matches!(map, @r###"
163 ⋮crate
164 ⋮foo: t
165
166 ⋮crate::foo
167 ⋮Baz: t v
168 ⋮bar: t
169
170 ⋮crate::foo::bar
171 ⋮Baz: t v
172 "###);
173}
174
175#[test]
176fn unresolved_module_diagnostics() {
177 let diagnostics = MockDatabase::with_files(
178 r"
179 //- /lib.rs
180 mod foo;
181 mod bar;
182 mod baz {}
183 //- /foo.rs
184 ",
185 )
186 .diagnostics();
187
188 assert_snapshot_matches!(diagnostics, @r###"
189"mod bar;": unresolved module
190"###
191 );
192}