aboutsummaryrefslogtreecommitdiff
path: root/crates/ra_ide_api/src/runnables.rs
diff options
context:
space:
mode:
authorAleksey Kladov <[email protected]>2019-01-14 13:27:08 +0000
committerAleksey Kladov <[email protected]>2019-01-15 11:18:24 +0000
commitd79a9b17dc4fb132443aa4ec1ca0ab278d2a217c (patch)
tree525b697381048b2f6d615a9c66c92485db8511ec /crates/ra_ide_api/src/runnables.rs
parent8caff4e03475c20392f13e8c6ad469bd01a4b4ce (diff)
switch to insta for testing
Diffstat (limited to 'crates/ra_ide_api/src/runnables.rs')
-rw-r--r--crates/ra_ide_api/src/runnables.rs97
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)]
97mod 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}