aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/tests/runnables.rs
blob: 9e5342c4625a1fef44b0b0ad03a843c8876b70b4 (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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
extern crate ra_analysis;
extern crate ra_editor;
extern crate ra_syntax;
extern crate relative_path;
extern crate rustc_hash;
extern crate test_utils;

use test_utils::assert_eq_dbg;

use ra_analysis::{
    mock_analysis::{analysis_and_position},
};

#[test]
fn test_runnables() {
    let (analysis, pos) = analysis_and_position(
        r#"
        //- /lib.rs
        <|> //empty
        fn main() {}

        #[test]
        fn test_foo() {}

        #[test]
        #[ignore]
        fn test_foo() {}
        "#,
    );
    let runnables = analysis.runnables(pos.file_id).unwrap();
    assert_eq_dbg(
        r#"[Runnable { range: [1; 21), kind: Bin },
                Runnable { range: [22; 46), kind: Test { name: "test_foo" } },
                Runnable { range: [47; 81), kind: Test { name: "test_foo" } }]"#,
        &runnables,
    )
}

#[test]
fn test_runnables_module() {
    let (analysis, pos) = analysis_and_position(
        r#"
        //- /lib.rs
        <|> //empty
        mod test_mod {
            #[test]
            fn test_foo1() {}
        }
        "#,
    );
    let runnables = analysis.runnables(pos.file_id).unwrap();
    assert_eq_dbg(
        r#"[Runnable { range: [1; 59), kind: TestMod { path: "test_mod" } },
                Runnable { range: [28; 57), kind: Test { name: "test_foo1" } }]"#,
        &runnables,
    )
}

#[test]
fn test_runnables_one_depth_layer_module() {
    let (analysis, pos) = analysis_and_position(
        r#"
        //- /lib.rs
        <|> //empty
        mod foo {
            mod test_mod {
                #[test]
                fn test_foo1() {}
            }
        }
        "#,
    );
    let runnables = analysis.runnables(pos.file_id).unwrap();
    assert_eq_dbg(
        r#"[Runnable { range: [23; 85), kind: TestMod { path: "foo::test_mod" } },
                Runnable { range: [46; 79), kind: Test { name: "test_foo1" } }]"#,
        &runnables,
    )
}

#[test]
fn test_runnables_multiple_depth_module() {
    let (analysis, pos) = analysis_and_position(
        r#"
        //- /lib.rs
        <|> //empty
        mod foo {
            mod bar {
                mod test_mod {
                    #[test]
                    fn test_foo1() {}
                }
            }
        }
        "#,
    );
    let runnables = analysis.runnables(pos.file_id).unwrap();
    assert_eq_dbg(
        r#"[Runnable { range: [41; 115), kind: TestMod { path: "foo::bar::test_mod" } },
                Runnable { range: [68; 105), kind: Test { name: "test_foo1" } }]"#,
        &runnables,
    )
}

#[test]
fn test_runnables_no_test_function_in_module() {
    let (analysis, pos) = analysis_and_position(
        r#"
        //- /lib.rs
        <|> //empty
        mod test_mod {
            fn foo1() {}
        }
        "#,
    );
    let runnables = analysis.runnables(pos.file_id).unwrap();
    assert_eq_dbg(r#"[]"#, &runnables)
}