diff options
Diffstat (limited to 'crates/ra_ide_api/src/runnables.rs')
-rw-r--r-- | crates/ra_ide_api/src/runnables.rs | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/crates/ra_ide_api/src/runnables.rs b/crates/ra_ide_api/src/runnables.rs index 53e49da5b..f1de28094 100644 --- a/crates/ra_ide_api/src/runnables.rs +++ b/crates/ra_ide_api/src/runnables.rs | |||
@@ -92,3 +92,100 @@ fn runnable_mod(db: &RootDatabase, file_id: FileId, module: &ast::Module) -> Opt | |||
92 | kind: RunnableKind::TestMod { path }, | 92 | kind: RunnableKind::TestMod { path }, |
93 | }) | 93 | }) |
94 | } | 94 | } |
95 | |||
96 | #[cfg(test)] | ||
97 | mod tests { | ||
98 | use insta::assert_debug_snapshot_matches; | ||
99 | |||
100 | use crate::mock_analysis::analysis_and_position; | ||
101 | |||
102 | #[test] | ||
103 | fn test_runnables() { | ||
104 | let (analysis, pos) = analysis_and_position( | ||
105 | r#" | ||
106 | //- /lib.rs | ||
107 | <|> //empty | ||
108 | fn main() {} | ||
109 | |||
110 | #[test] | ||
111 | fn test_foo() {} | ||
112 | |||
113 | #[test] | ||
114 | #[ignore] | ||
115 | fn test_foo() {} | ||
116 | "#, | ||
117 | ); | ||
118 | let runnables = analysis.runnables(pos.file_id).unwrap(); | ||
119 | assert_debug_snapshot_matches!("runnables", &runnables) | ||
120 | } | ||
121 | |||
122 | #[test] | ||
123 | fn test_runnables_module() { | ||
124 | let (analysis, pos) = analysis_and_position( | ||
125 | r#" | ||
126 | //- /lib.rs | ||
127 | <|> //empty | ||
128 | mod test_mod { | ||
129 | #[test] | ||
130 | fn test_foo1() {} | ||
131 | } | ||
132 | "#, | ||
133 | ); | ||
134 | let runnables = analysis.runnables(pos.file_id).unwrap(); | ||
135 | assert_debug_snapshot_matches!("runnables_module", &runnables) | ||
136 | } | ||
137 | |||
138 | #[test] | ||
139 | fn test_runnables_one_depth_layer_module() { | ||
140 | let (analysis, pos) = analysis_and_position( | ||
141 | r#" | ||
142 | //- /lib.rs | ||
143 | <|> //empty | ||
144 | mod foo { | ||
145 | mod test_mod { | ||
146 | #[test] | ||
147 | fn test_foo1() {} | ||
148 | } | ||
149 | } | ||
150 | "#, | ||
151 | ); | ||
152 | let runnables = analysis.runnables(pos.file_id).unwrap(); | ||
153 | assert_debug_snapshot_matches!("runnables_one_depth_layer_module", &runnables) | ||
154 | } | ||
155 | |||
156 | #[test] | ||
157 | fn test_runnables_multiple_depth_module() { | ||
158 | let (analysis, pos) = analysis_and_position( | ||
159 | r#" | ||
160 | //- /lib.rs | ||
161 | <|> //empty | ||
162 | mod foo { | ||
163 | mod bar { | ||
164 | mod test_mod { | ||
165 | #[test] | ||
166 | fn test_foo1() {} | ||
167 | } | ||
168 | } | ||
169 | } | ||
170 | "#, | ||
171 | ); | ||
172 | let runnables = analysis.runnables(pos.file_id).unwrap(); | ||
173 | assert_debug_snapshot_matches!("runnables_multiple_depth_module", &runnables) | ||
174 | } | ||
175 | |||
176 | #[test] | ||
177 | fn test_runnables_no_test_function_in_module() { | ||
178 | let (analysis, pos) = analysis_and_position( | ||
179 | r#" | ||
180 | //- /lib.rs | ||
181 | <|> //empty | ||
182 | mod test_mod { | ||
183 | fn foo1() {} | ||
184 | } | ||
185 | "#, | ||
186 | ); | ||
187 | let runnables = analysis.runnables(pos.file_id).unwrap(); | ||
188 | assert!(runnables.is_empty()) | ||
189 | } | ||
190 | |||
191 | } | ||