aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src/ty/tests.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_hir/src/ty/tests.rs')
-rw-r--r--crates/ra_hir/src/ty/tests.rs84
1 files changed, 25 insertions, 59 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index f27155737..4b7e34878 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -2,8 +2,7 @@ use std::fmt::Write;
2use std::sync::Arc; 2use std::sync::Arc;
3 3
4use insta::assert_snapshot; 4use insta::assert_snapshot;
5 5use ra_db::{fixture::WithFixture, salsa::Database, FilePosition, SourceDatabase};
6use ra_db::{salsa::Database, FilePosition, SourceDatabase};
7use ra_syntax::{ 6use ra_syntax::{
8 algo, 7 algo,
9 ast::{self, AstNode}, 8 ast::{self, AstNode},
@@ -25,9 +24,9 @@ mod coercion;
25 24
26#[test] 25#[test]
27fn cfg_impl_block() { 26fn cfg_impl_block() {
28 let (mut db, pos) = MockDatabase::with_position( 27 let (db, pos) = MockDatabase::with_position(
29 r#" 28 r#"
30//- /main.rs 29//- /main.rs crate:main deps:foo cfg:test
31use foo::S as T; 30use foo::S as T;
32struct S; 31struct S;
33 32
@@ -46,7 +45,7 @@ fn test() {
46 t<|>; 45 t<|>;
47} 46}
48 47
49//- /foo.rs 48//- /foo.rs crate:foo
50struct S; 49struct S;
51 50
52#[cfg(not(test))] 51#[cfg(not(test))]
@@ -60,18 +59,14 @@ impl S {
60} 59}
61"#, 60"#,
62 ); 61 );
63 db.set_crate_graph_from_fixture(crate_graph! {
64 "main": ("/main.rs", ["foo"], cfg = { "test" }),
65 "foo": ("/foo.rs", []),
66 });
67 assert_eq!("(i32, {unknown}, i32, {unknown})", type_at_pos(&db, pos)); 62 assert_eq!("(i32, {unknown}, i32, {unknown})", type_at_pos(&db, pos));
68} 63}
69 64
70#[test] 65#[test]
71fn infer_await() { 66fn infer_await() {
72 let (mut db, pos) = MockDatabase::with_position( 67 let (db, pos) = MockDatabase::with_position(
73 r#" 68 r#"
74//- /main.rs 69//- /main.rs crate:main deps:std
75 70
76struct IntFuture; 71struct IntFuture;
77 72
@@ -85,7 +80,7 @@ fn test() {
85 v<|>; 80 v<|>;
86} 81}
87 82
88//- /std.rs 83//- /std.rs crate:std
89#[prelude_import] use future::*; 84#[prelude_import] use future::*;
90mod future { 85mod future {
91 trait Future { 86 trait Future {
@@ -95,18 +90,14 @@ mod future {
95 90
96"#, 91"#,
97 ); 92 );
98 db.set_crate_graph_from_fixture(crate_graph! {
99 "main": ("/main.rs", ["std"]),
100 "std": ("/std.rs", []),
101 });
102 assert_eq!("u64", type_at_pos(&db, pos)); 93 assert_eq!("u64", type_at_pos(&db, pos));
103} 94}
104 95
105#[test] 96#[test]
106fn infer_box() { 97fn infer_box() {
107 let (mut db, pos) = MockDatabase::with_position( 98 let (db, pos) = MockDatabase::with_position(
108 r#" 99 r#"
109//- /main.rs 100//- /main.rs crate:main deps:std
110 101
111fn test() { 102fn test() {
112 let x = box 1; 103 let x = box 1;
@@ -114,7 +105,7 @@ fn test() {
114 t<|>; 105 t<|>;
115} 106}
116 107
117//- /std.rs 108//- /std.rs crate:std
118#[prelude_import] use prelude::*; 109#[prelude_import] use prelude::*;
119mod prelude {} 110mod prelude {}
120 111
@@ -126,10 +117,6 @@ mod boxed {
126 117
127"#, 118"#,
128 ); 119 );
129 db.set_crate_graph_from_fixture(crate_graph! {
130 "main": ("/main.rs", ["std"]),
131 "std": ("/std.rs", []),
132 });
133 assert_eq!("(Box<i32>, Box<Box<i32>>, Box<&i32>, Box<[i32;_]>)", type_at_pos(&db, pos)); 120 assert_eq!("(Box<i32>, Box<Box<i32>>, Box<&i32>, Box<[i32;_]>)", type_at_pos(&db, pos));
134} 121}
135 122
@@ -154,9 +141,9 @@ fn test() {
154 141
155#[test] 142#[test]
156fn infer_try() { 143fn infer_try() {
157 let (mut db, pos) = MockDatabase::with_position( 144 let (db, pos) = MockDatabase::with_position(
158 r#" 145 r#"
159//- /main.rs 146//- /main.rs crate:main deps:std
160 147
161fn test() { 148fn test() {
162 let r: Result<i32, u64> = Result::Ok(1); 149 let r: Result<i32, u64> = Result::Ok(1);
@@ -164,7 +151,7 @@ fn test() {
164 v<|>; 151 v<|>;
165} 152}
166 153
167//- /std.rs 154//- /std.rs crate:std
168 155
169#[prelude_import] use ops::*; 156#[prelude_import] use ops::*;
170mod ops { 157mod ops {
@@ -189,18 +176,14 @@ mod result {
189 176
190"#, 177"#,
191 ); 178 );
192 db.set_crate_graph_from_fixture(crate_graph! {
193 "main": ("/main.rs", ["std"]),
194 "std": ("/std.rs", []),
195 });
196 assert_eq!("i32", type_at_pos(&db, pos)); 179 assert_eq!("i32", type_at_pos(&db, pos));
197} 180}
198 181
199#[test] 182#[test]
200fn infer_for_loop() { 183fn infer_for_loop() {
201 let (mut db, pos) = MockDatabase::with_position( 184 let (db, pos) = MockDatabase::with_position(
202 r#" 185 r#"
203//- /main.rs 186//- /main.rs crate:main deps:std
204 187
205use std::collections::Vec; 188use std::collections::Vec;
206 189
@@ -212,7 +195,7 @@ fn test() {
212 } 195 }
213} 196}
214 197
215//- /std.rs 198//- /std.rs crate:std
216 199
217#[prelude_import] use iter::*; 200#[prelude_import] use iter::*;
218mod iter { 201mod iter {
@@ -234,10 +217,6 @@ mod collections {
234} 217}
235"#, 218"#,
236 ); 219 );
237 db.set_crate_graph_from_fixture(crate_graph! {
238 "main": ("/main.rs", ["std"]),
239 "std": ("/std.rs", []),
240 });
241 assert_eq!("&str", type_at_pos(&db, pos)); 220 assert_eq!("&str", type_at_pos(&db, pos));
242} 221}
243 222
@@ -2505,15 +2484,15 @@ pub fn main_loop() {
2505 2484
2506#[test] 2485#[test]
2507fn cross_crate_associated_method_call() { 2486fn cross_crate_associated_method_call() {
2508 let (mut db, pos) = MockDatabase::with_position( 2487 let (db, pos) = MockDatabase::with_position(
2509 r#" 2488 r#"
2510//- /main.rs 2489//- /main.rs crate:main deps:other_crate
2511fn test() { 2490fn test() {
2512 let x = other_crate::foo::S::thing(); 2491 let x = other_crate::foo::S::thing();
2513 x<|>; 2492 x<|>;
2514} 2493}
2515 2494
2516//- /lib.rs 2495//- /lib.rs crate:other_crate
2517mod foo { 2496mod foo {
2518 struct S; 2497 struct S;
2519 impl S { 2498 impl S {
@@ -2522,10 +2501,6 @@ mod foo {
2522} 2501}
2523"#, 2502"#,
2524 ); 2503 );
2525 db.set_crate_graph_from_fixture(crate_graph! {
2526 "main": ("/main.rs", ["other_crate"]),
2527 "other_crate": ("/lib.rs", []),
2528 });
2529 assert_eq!("i128", type_at_pos(&db, pos)); 2504 assert_eq!("i128", type_at_pos(&db, pos));
2530} 2505}
2531 2506
@@ -3403,16 +3378,15 @@ fn test() { S.foo()<|>; }
3403 3378
3404#[test] 3379#[test]
3405fn infer_macro_with_dollar_crate_is_correct_in_expr() { 3380fn infer_macro_with_dollar_crate_is_correct_in_expr() {
3406 // covers!(macro_dollar_crate_other); 3381 let (db, pos) = MockDatabase::with_position(
3407 let (mut db, pos) = MockDatabase::with_position(
3408 r#" 3382 r#"
3409//- /main.rs 3383//- /main.rs crate:main deps:foo
3410fn test() { 3384fn test() {
3411 let x = (foo::foo!(1), foo::foo!(2)); 3385 let x = (foo::foo!(1), foo::foo!(2));
3412 x<|>; 3386 x<|>;
3413} 3387}
3414 3388
3415//- /lib.rs 3389//- /lib.rs crate:foo
3416#[macro_export] 3390#[macro_export]
3417macro_rules! foo { 3391macro_rules! foo {
3418 (1) => { $crate::bar!() }; 3392 (1) => { $crate::bar!() };
@@ -3427,10 +3401,6 @@ macro_rules! bar {
3427pub fn baz() -> usize { 31usize } 3401pub fn baz() -> usize { 31usize }
3428"#, 3402"#,
3429 ); 3403 );
3430 db.set_crate_graph_from_fixture(crate_graph! {
3431 "main": ("/main.rs", ["foo"]),
3432 "foo": ("/lib.rs", []),
3433 });
3434 assert_eq!("(i32, usize)", type_at_pos(&db, pos)); 3404 assert_eq!("(i32, usize)", type_at_pos(&db, pos));
3435} 3405}
3436 3406
@@ -3512,9 +3482,9 @@ fn test() { (&S).foo()<|>; }
3512 3482
3513#[test] 3483#[test]
3514fn method_resolution_trait_from_prelude() { 3484fn method_resolution_trait_from_prelude() {
3515 let (mut db, pos) = MockDatabase::with_position( 3485 let (db, pos) = MockDatabase::with_position(
3516 r#" 3486 r#"
3517//- /main.rs 3487//- /main.rs crate:main deps:other_crate
3518struct S; 3488struct S;
3519impl Clone for S {} 3489impl Clone for S {}
3520 3490
@@ -3522,7 +3492,7 @@ fn test() {
3522 S.clone()<|>; 3492 S.clone()<|>;
3523} 3493}
3524 3494
3525//- /lib.rs 3495//- /lib.rs crate:other_crate
3526#[prelude_import] use foo::*; 3496#[prelude_import] use foo::*;
3527 3497
3528mod foo { 3498mod foo {
@@ -3532,10 +3502,6 @@ mod foo {
3532} 3502}
3533"#, 3503"#,
3534 ); 3504 );
3535 db.set_crate_graph_from_fixture(crate_graph! {
3536 "main": ("/main.rs", ["other_crate"]),
3537 "other_crate": ("/lib.rs", []),
3538 });
3539 assert_eq!("S", type_at_pos(&db, pos)); 3505 assert_eq!("S", type_at_pos(&db, pos));
3540} 3506}
3541 3507