Skip to content

Commit 9a0d4b1

Browse files
committed
beautify tests
1 parent 741fc8f commit 9a0d4b1

File tree

1 file changed

+36
-20
lines changed

1 file changed

+36
-20
lines changed

crates/ra_hir/src/ty/tests.rs

Lines changed: 36 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -25,33 +25,41 @@ fn infer_try() {
2525
let (mut db, pos) = MockDatabase::with_position(
2626
r#"
2727
//- /main.rs
28-
enum Result<O, E> {
29-
Ok(O),
30-
Err(E)
31-
}
3228
33-
impl<O, E> ::std::ops::Try for Result<O, E> {
34-
type Ok = O;
35-
type Error = E;
36-
}
3729
fn test() {
3830
let r: Result<i32, u64> = Result::Ok(1);
3931
let v = r?;
4032
v<|>;
4133
}
4234
43-
//- /lib.rs
35+
//- /std.rs
36+
37+
#[prelude_import] use ops::*;
4438
mod ops {
4539
trait Try {
4640
type Ok;
4741
type Error;
4842
}
4943
}
44+
45+
#[prelude_import] use result::*;
46+
mod result {
47+
enum Result<O, E> {
48+
Ok(O),
49+
Err(E)
50+
}
51+
52+
impl<O, E> crate::ops::Try for Result<O, E> {
53+
type Ok = O;
54+
type Error = E;
55+
}
56+
}
57+
5058
"#,
5159
);
5260
db.set_crate_graph_from_fixture(crate_graph! {
5361
"main": ("/main.rs", ["std"]),
54-
"std": ("/lib.rs", []),
62+
"std": ("/std.rs", []),
5563
});
5664
assert_eq!("i32", type_at_pos(&db, pos));
5765
}
@@ -61,15 +69,9 @@ fn infer_for_loop() {
6169
let (mut db, pos) = MockDatabase::with_position(
6270
r#"
6371
//- /main.rs
64-
struct Vec<T> {}
65-
impl<T> Vec<T> {
66-
fn new() -> Self { Vec {} }
67-
fn push(&mut self, t: T) { }
68-
}
6972
70-
impl<T> ::std::iter::IntoIterator for Vec<T> {
71-
type Item=T;
72-
}
73+
use std::collections::Vec;
74+
7375
fn test() {
7476
let v = Vec::new();
7577
v.push("foo");
@@ -78,17 +80,31 @@ fn test() {
7880
}
7981
}
8082
81-
//- /lib.rs
83+
//- /std.rs
84+
85+
#[prelude_import] use iter::*;
8286
mod iter {
8387
trait IntoIterator {
8488
type Item;
8589
}
8690
}
91+
92+
mod collections {
93+
struct Vec<T> {}
94+
impl<T> Vec<T> {
95+
fn new() -> Self { Vec {} }
96+
fn push(&mut self, t: T) { }
97+
}
98+
99+
impl<T> crate::iter::IntoIterator for Vec<T> {
100+
type Item=T;
101+
}
102+
}
87103
"#,
88104
);
89105
db.set_crate_graph_from_fixture(crate_graph! {
90106
"main": ("/main.rs", ["std"]),
91-
"std": ("/lib.rs", []),
107+
"std": ("/std.rs", []),
92108
});
93109
assert_eq!("&str", type_at_pos(&db, pos));
94110
}

0 commit comments

Comments
 (0)