aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_analysis/tests/runnables.rs
diff options
context:
space:
mode:
Diffstat (limited to 'crates/ra_analysis/tests/runnables.rs')
-rw-r--r--crates/ra_analysis/tests/runnables.rs118
1 files changed, 118 insertions, 0 deletions
diff --git a/crates/ra_analysis/tests/runnables.rs b/crates/ra_analysis/tests/runnables.rs
new file mode 100644
index 000000000..9e5342c46
--- /dev/null
+++ b/crates/ra_analysis/tests/runnables.rs
@@ -0,0 +1,118 @@
1extern crate ra_analysis;
2extern crate ra_editor;
3extern crate ra_syntax;
4extern crate relative_path;
5extern crate rustc_hash;
6extern crate test_utils;
7
8use test_utils::assert_eq_dbg;
9
10use ra_analysis::{
11 mock_analysis::{analysis_and_position},
12};
13
14#[test]
15fn test_runnables() {
16 let (analysis, pos) = analysis_and_position(
17 r#"
18 //- /lib.rs
19 <|> //empty
20 fn main() {}
21
22 #[test]
23 fn test_foo() {}
24
25 #[test]
26 #[ignore]
27 fn test_foo() {}
28 "#,
29 );
30 let runnables = analysis.runnables(pos.file_id).unwrap();
31 assert_eq_dbg(
32 r#"[Runnable { range: [1; 21), kind: Bin },
33 Runnable { range: [22; 46), kind: Test { name: "test_foo" } },
34 Runnable { range: [47; 81), kind: Test { name: "test_foo" } }]"#,
35 &runnables,
36 )
37}
38
39#[test]
40fn test_runnables_module() {
41 let (analysis, pos) = analysis_and_position(
42 r#"
43 //- /lib.rs
44 <|> //empty
45 mod test_mod {
46 #[test]
47 fn test_foo1() {}
48 }
49 "#,
50 );
51 let runnables = analysis.runnables(pos.file_id).unwrap();
52 assert_eq_dbg(
53 r#"[Runnable { range: [1; 59), kind: TestMod { path: "test_mod" } },
54 Runnable { range: [28; 57), kind: Test { name: "test_foo1" } }]"#,
55 &runnables,
56 )
57}
58
59#[test]
60fn test_runnables_one_depth_layer_module() {
61 let (analysis, pos) = analysis_and_position(
62 r#"
63 //- /lib.rs
64 <|> //empty
65 mod foo {
66 mod test_mod {
67 #[test]
68 fn test_foo1() {}
69 }
70 }
71 "#,
72 );
73 let runnables = analysis.runnables(pos.file_id).unwrap();
74 assert_eq_dbg(
75 r#"[Runnable { range: [23; 85), kind: TestMod { path: "foo::test_mod" } },
76 Runnable { range: [46; 79), kind: Test { name: "test_foo1" } }]"#,
77 &runnables,
78 )
79}
80
81#[test]
82fn test_runnables_multiple_depth_module() {
83 let (analysis, pos) = analysis_and_position(
84 r#"
85 //- /lib.rs
86 <|> //empty
87 mod foo {
88 mod bar {
89 mod test_mod {
90 #[test]
91 fn test_foo1() {}
92 }
93 }
94 }
95 "#,
96 );
97 let runnables = analysis.runnables(pos.file_id).unwrap();
98 assert_eq_dbg(
99 r#"[Runnable { range: [41; 115), kind: TestMod { path: "foo::bar::test_mod" } },
100 Runnable { range: [68; 105), kind: Test { name: "test_foo1" } }]"#,
101 &runnables,
102 )
103}
104
105#[test]
106fn test_runnables_no_test_function_in_module() {
107 let (analysis, pos) = analysis_and_position(
108 r#"
109 //- /lib.rs
110 <|> //empty
111 mod test_mod {
112 fn foo1() {}
113 }
114 "#,
115 );
116 let runnables = analysis.runnables(pos.file_id).unwrap();
117 assert_eq_dbg(r#"[]"#, &runnables)
118}