Deive type_of test from tests

This commit is contained in:
Hirokazu Hata 2019-01-03 18:48:03 +09:00
parent f99e96698c
commit 4363e7b9b2
2 changed files with 80 additions and 17 deletions

View file

@ -2,7 +2,7 @@ use ra_syntax::TextRange;
use test_utils::{assert_eq_dbg, assert_eq_text};
use ra_analysis::{
mock_analysis::{analysis_and_position, analysis_and_range, single_file, single_file_with_position, MockAnalysis},
mock_analysis::{analysis_and_position, single_file, single_file_with_position, MockAnalysis},
AnalysisChange, CrateGraph, FileId, FnSignatureInfo,
};
@ -10,22 +10,6 @@ fn get_signature(text: &str) -> (FnSignatureInfo, Option<usize>) {
let (analysis, position) = single_file_with_position(text);
analysis.resolve_callable(position).unwrap().unwrap()
}
#[test]
fn test_type_of() {
let (analysis, range) = analysis_and_range(
"
//- /lib.rs
pub fn foo() -> u32 {
1
};
let <|>foo_test<|> = foo();
",
);
let type_name = analysis.type_of(range).unwrap().unwrap();
assert_eq_dbg("u32", &type_name);
}
#[test]
fn approximate_resolve_works_in_items() {

View file

@ -0,0 +1,79 @@
use ra_analysis::{
mock_analysis::{single_file_with_range},
};
#[test]
fn test_type_of_for_function() {
let (analysis, range) = single_file_with_range(
"
pub fn foo() -> u32 { 1 };
fn main() {
let foo_test = <|>foo()<|>;
}
",
);
let type_name = analysis.type_of(range).unwrap().unwrap();
assert_eq!("u32", &type_name);
}
// FIXME: improve type_of to make this work
#[test]
fn test_type_of_for_num() {
let (analysis, range) = single_file_with_range(
r#"
fn main() {
let foo_test = <|>"foo"<|>;
}
"#,
);
assert!(analysis.type_of(range).unwrap().is_none());
}
// FIXME: improve type_of to make this work
#[test]
fn test_type_of_for_binding() {
let (analysis, range) = single_file_with_range(
"
pub fn foo() -> u32 { 1 };
fn main() {
let <|>foo_test<|> = foo();
}
",
);
assert!(analysis.type_of(range).unwrap().is_none());
}
// FIXME: improve type_of to make this work
#[test]
fn test_type_of_for_expr_1() {
let (analysis, range) = single_file_with_range(
"
fn main() {
let foo = <|>1 + foo_test<|>;
}
",
);
let type_name = analysis.type_of(range).unwrap().unwrap();
assert_eq!("[unknown]", &type_name);
}
// FIXME: improve type_of to make this work
#[test]
fn test_type_of_for_expr_2() {
let (analysis, range) = single_file_with_range(
"
fn main() {
let foo: usize = 1;
let bar = <|>1 + foo_test<|>;
}
",
);
let type_name = analysis.type_of(range).unwrap().unwrap();
assert_eq!("[unknown]", &type_name);
}