aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_hir_ty/src/tests/display_source_code.rs
blob: 4088b1d22d9463bab869d349c9f8d5da62f20bcb (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
use super::displayed_source_at_pos;
use crate::test_db::TestDB;
use ra_db::fixture::WithFixture;

#[test]
fn qualify_path_to_submodule() {
    let (db, pos) = TestDB::with_position(
        r#"
//- /main.rs

mod foo {
    pub struct Foo;
}

fn bar() {
    let foo: foo::Foo = foo::Foo;
    foo<|>
}

"#,
    );
    assert_eq!("foo::Foo", displayed_source_at_pos(&db, pos));
}

#[test]
fn omit_default_type_parameters() {
    let (db, pos) = TestDB::with_position(
        r"
        //- /main.rs
        struct Foo<T = u8> { t: T }
        fn main() {
            let foo = Foo { t: 5 };
            foo<|>;
        }
        ",
    );
    assert_eq!("Foo", displayed_source_at_pos(&db, pos));

    let (db, pos) = TestDB::with_position(
        r"
        //- /main.rs
        struct Foo<K, T = u8> { k: K, t: T }
        fn main() {
            let foo = Foo { k: 400, t: 5 };
            foo<|>;
        }
        ",
    );
    assert_eq!("Foo<i32>", displayed_source_at_pos(&db, pos));
}