aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/tests/test/type_of.rs
blob: 9d15b52a889d5fa4048633bcb9825e39e6456c19 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
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);
}