mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
beautify tests
This commit is contained in:
parent
741fc8fbfc
commit
9a0d4b16b7
1 changed files with 36 additions and 20 deletions
|
@ -25,33 +25,41 @@ fn infer_try() {
|
||||||
let (mut db, pos) = MockDatabase::with_position(
|
let (mut db, pos) = MockDatabase::with_position(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
enum Result<O, E> {
|
|
||||||
Ok(O),
|
|
||||||
Err(E)
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<O, E> ::std::ops::Try for Result<O, E> {
|
|
||||||
type Ok = O;
|
|
||||||
type Error = E;
|
|
||||||
}
|
|
||||||
fn test() {
|
fn test() {
|
||||||
let r: Result<i32, u64> = Result::Ok(1);
|
let r: Result<i32, u64> = Result::Ok(1);
|
||||||
let v = r?;
|
let v = r?;
|
||||||
v<|>;
|
v<|>;
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /lib.rs
|
//- /std.rs
|
||||||
|
|
||||||
|
#[prelude_import] use ops::*;
|
||||||
mod ops {
|
mod ops {
|
||||||
trait Try {
|
trait Try {
|
||||||
type Ok;
|
type Ok;
|
||||||
type Error;
|
type Error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[prelude_import] use result::*;
|
||||||
|
mod result {
|
||||||
|
enum Result<O, E> {
|
||||||
|
Ok(O),
|
||||||
|
Err(E)
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<O, E> crate::ops::Try for Result<O, E> {
|
||||||
|
type Ok = O;
|
||||||
|
type Error = E;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
db.set_crate_graph_from_fixture(crate_graph! {
|
db.set_crate_graph_from_fixture(crate_graph! {
|
||||||
"main": ("/main.rs", ["std"]),
|
"main": ("/main.rs", ["std"]),
|
||||||
"std": ("/lib.rs", []),
|
"std": ("/std.rs", []),
|
||||||
});
|
});
|
||||||
assert_eq!("i32", type_at_pos(&db, pos));
|
assert_eq!("i32", type_at_pos(&db, pos));
|
||||||
}
|
}
|
||||||
|
@ -61,15 +69,9 @@ fn infer_for_loop() {
|
||||||
let (mut db, pos) = MockDatabase::with_position(
|
let (mut db, pos) = MockDatabase::with_position(
|
||||||
r#"
|
r#"
|
||||||
//- /main.rs
|
//- /main.rs
|
||||||
struct Vec<T> {}
|
|
||||||
impl<T> Vec<T> {
|
|
||||||
fn new() -> Self { Vec {} }
|
|
||||||
fn push(&mut self, t: T) { }
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<T> ::std::iter::IntoIterator for Vec<T> {
|
use std::collections::Vec;
|
||||||
type Item=T;
|
|
||||||
}
|
|
||||||
fn test() {
|
fn test() {
|
||||||
let v = Vec::new();
|
let v = Vec::new();
|
||||||
v.push("foo");
|
v.push("foo");
|
||||||
|
@ -78,17 +80,31 @@ fn test() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//- /lib.rs
|
//- /std.rs
|
||||||
|
|
||||||
|
#[prelude_import] use iter::*;
|
||||||
mod iter {
|
mod iter {
|
||||||
trait IntoIterator {
|
trait IntoIterator {
|
||||||
type Item;
|
type Item;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
mod collections {
|
||||||
|
struct Vec<T> {}
|
||||||
|
impl<T> Vec<T> {
|
||||||
|
fn new() -> Self { Vec {} }
|
||||||
|
fn push(&mut self, t: T) { }
|
||||||
|
}
|
||||||
|
|
||||||
|
impl<T> crate::iter::IntoIterator for Vec<T> {
|
||||||
|
type Item=T;
|
||||||
|
}
|
||||||
|
}
|
||||||
"#,
|
"#,
|
||||||
);
|
);
|
||||||
db.set_crate_graph_from_fixture(crate_graph! {
|
db.set_crate_graph_from_fixture(crate_graph! {
|
||||||
"main": ("/main.rs", ["std"]),
|
"main": ("/main.rs", ["std"]),
|
||||||
"std": ("/lib.rs", []),
|
"std": ("/std.rs", []),
|
||||||
});
|
});
|
||||||
assert_eq!("&str", type_at_pos(&db, pos));
|
assert_eq!("&str", type_at_pos(&db, pos));
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue