From 9a0d4b16b7d14530b77c96e2e18b80b3f5b526c8 Mon Sep 17 00:00:00 2001 From: Unreal Hoang Date: Tue, 9 Jul 2019 01:01:07 +0900 Subject: beautify tests --- crates/ra_hir/src/ty/tests.rs | 56 +++++++++++++++++++++++++++---------------- 1 file 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() { let (mut db, pos) = MockDatabase::with_position( r#" //- /main.rs -enum Result { - Ok(O), - Err(E) -} -impl ::std::ops::Try for Result { - type Ok = O; - type Error = E; -} fn test() { let r: Result = Result::Ok(1); let v = r?; v<|>; } -//- /lib.rs +//- /std.rs + +#[prelude_import] use ops::*; mod ops { trait Try { type Ok; type Error; } } + +#[prelude_import] use result::*; +mod result { + enum Result { + Ok(O), + Err(E) + } + + impl crate::ops::Try for Result { + type Ok = O; + type Error = E; + } +} + "#, ); db.set_crate_graph_from_fixture(crate_graph! { "main": ("/main.rs", ["std"]), - "std": ("/lib.rs", []), + "std": ("/std.rs", []), }); assert_eq!("i32", type_at_pos(&db, pos)); } @@ -61,15 +69,9 @@ fn infer_for_loop() { let (mut db, pos) = MockDatabase::with_position( r#" //- /main.rs -struct Vec {} -impl Vec { - fn new() -> Self { Vec {} } - fn push(&mut self, t: T) { } -} -impl ::std::iter::IntoIterator for Vec { - type Item=T; -} +use std::collections::Vec; + fn test() { let v = Vec::new(); v.push("foo"); @@ -78,17 +80,31 @@ fn test() { } } -//- /lib.rs +//- /std.rs + +#[prelude_import] use iter::*; mod iter { trait IntoIterator { type Item; } } + +mod collections { + struct Vec {} + impl Vec { + fn new() -> Self { Vec {} } + fn push(&mut self, t: T) { } + } + + impl crate::iter::IntoIterator for Vec { + type Item=T; + } +} "#, ); db.set_crate_graph_from_fixture(crate_graph! { "main": ("/main.rs", ["std"]), - "std": ("/lib.rs", []), + "std": ("/std.rs", []), }); assert_eq!("&str", type_at_pos(&db, pos)); } -- cgit v1.2.3