MCPcopy Create free account
hub / github.com/astral-sh/ruff / collect_tests

Function collect_tests

crates/ruff_python_parser/tests/generate_inline_tests.rs:211–240  ·  view source on GitHub ↗

Collect the tests from the given source text.

(text: &str)

Source from the content-addressed store, hash-verified

209
210/// Collect the tests from the given source text.
211fn collect_tests(text: &str) -> Vec<Test> {
212 let mut tests = Vec::new();
213
214 for comment_block in extract_comment_blocks(text) {
215 let first_line = &comment_block[0];
216
217 let (kind, name) = match first_line.split_once(' ') {
218 Some(("test_ok", suffix)) => (TestKind::Ok, suffix),
219 Some(("test_err", suffix)) => (TestKind::Err, suffix),
220 _ => continue,
221 };
222
223 let text: String = comment_block[1..]
224 .iter()
225 .cloned()
226 .chain([String::new()])
227 .collect::<Vec<_>>()
228 .join("\n");
229
230 assert!(!text.trim().is_empty() && text.ends_with('\n'));
231
232 tests.push(Test {
233 name: name.to_string(),
234 contents: text,
235 kind,
236 });
237 }
238
239 tests
240}
241
242#[derive(Debug, Default)]
243struct CommentBlock(Vec<String>);

Callers 1

try_fromMethod · 0.85

Calls 5

extract_comment_blocksFunction · 0.85
joinMethod · 0.45
iterMethod · 0.45
pushMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected