aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir/src
diff options
context:
space:
mode:
authorUnreal Hoang <[email protected]>2019-07-08 17:01:07 +0100
committerUnreal Hoang <[email protected]>2019-07-09 01:27:03 +0100
commit9a0d4b16b7d14530b77c96e2e18b80b3f5b526c8 (patch)
tree302eb3a8ee8b69917fa03ed242b884f848f92445 /crates/ra_hir/src
parent741fc8fbfc10445ef90c8234e042d688d8bc293b (diff)
beautify tests
Diffstat (limited to 'crates/ra_hir/src')
-rw-r--r--crates/ra_hir/src/ty/tests.rs56
1 files changed, 36 insertions, 20 deletions
diff --git a/crates/ra_hir/src/ty/tests.rs b/crates/ra_hir/src/ty/tests.rs
index d5c03c4bc..6aea1fb4a 100644
--- a/crates/ra_hir/src/ty/tests.rs
+++ b/crates/ra_hir/src/ty/tests.rs
@@ -25,33 +25,41 @@ fn infer_try() {
25 let (mut db, pos) = MockDatabase::with_position( 25 let (mut db, pos) = MockDatabase::with_position(
26 r#" 26 r#"
27//- /main.rs 27//- /main.rs
28enum Result<O, E> {
29 Ok(O),
30 Err(E)
31}
32 28
33impl<O, E> ::std::ops::Try for Result<O, E> {
34 type Ok = O;
35 type Error = E;
36}
37fn test() { 29fn test() {
38 let r: Result<i32, u64> = Result::Ok(1); 30 let r: Result<i32, u64> = Result::Ok(1);
39 let v = r?; 31 let v = r?;
40 v<|>; 32 v<|>;
41} 33}
42 34
43//- /lib.rs 35//- /std.rs
36
37#[prelude_import] use ops::*;
44mod ops { 38mod ops {
45 trait Try { 39 trait Try {
46 type Ok; 40 type Ok;
47 type Error; 41 type Error;
48 } 42 }
49} 43}
44
45#[prelude_import] use result::*;
46mod 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
50"#, 58"#,
51 ); 59 );
52 db.set_crate_graph_from_fixture(crate_graph! { 60 db.set_crate_graph_from_fixture(crate_graph! {
53 "main": ("/main.rs", ["std"]), 61 "main": ("/main.rs", ["std"]),
54 "std": ("/lib.rs", []), 62 "std": ("/std.rs", []),
55 }); 63 });
56 assert_eq!("i32", type_at_pos(&db, pos)); 64 assert_eq!("i32", type_at_pos(&db, pos));
57} 65}
@@ -61,15 +69,9 @@ fn infer_for_loop() {
61 let (mut db, pos) = MockDatabase::with_position( 69 let (mut db, pos) = MockDatabase::with_position(
62 r#" 70 r#"
63//- /main.rs 71//- /main.rs
64struct Vec<T> {}
65impl<T> Vec<T> {
66 fn new() -> Self { Vec {} }
67 fn push(&mut self, t: T) { }
68}
69 72
70impl<T> ::std::iter::IntoIterator for Vec<T> { 73use std::collections::Vec;
71 type Item=T; 74
72}
73fn test() { 75fn test() {
74 let v = Vec::new(); 76 let v = Vec::new();
75 v.push("foo"); 77 v.push("foo");
@@ -78,17 +80,31 @@ fn test() {
78 } 80 }
79} 81}
80 82
81//- /lib.rs 83//- /std.rs
84
85#[prelude_import] use iter::*;
82mod iter { 86mod iter {
83 trait IntoIterator { 87 trait IntoIterator {
84 type Item; 88 type Item;
85 } 89 }
86} 90}
91
92mod 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}
87"#, 103"#,
88 ); 104 );
89 db.set_crate_graph_from_fixture(crate_graph! { 105 db.set_crate_graph_from_fixture(crate_graph! {
90 "main": ("/main.rs", ["std"]), 106 "main": ("/main.rs", ["std"]),
91 "std": ("/lib.rs", []), 107 "std": ("/std.rs", []),
92 }); 108 });
93 assert_eq!("&str", type_at_pos(&db, pos)); 109 assert_eq!("&str", type_at_pos(&db, pos));
94} 110}