Skip to content

Commit

Permalink
try to clean up iterators
Browse files Browse the repository at this point in the history
  • Loading branch information
pilleye committed Oct 18, 2024
1 parent 545f85e commit 77355c6
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions crates/red_knot_test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,21 @@ pub fn run(path: &PathBuf, title: &str) {
any_failures = true;
println!("\n{}\n", test.name().bold().underline());

for (lined_path, by_line) in failures {
println!("{}", lined_path.path.as_str().bold());
for (
AbsoluteLineNumberPath {
path,
line_number: absolute_line_number,
},
by_line,
) in failures
{
println!("{}", path.as_str().bold());
for (line_number, failures) in by_line.iter() {
for failure in failures {
let absolute_line_info = format!(
"{}:{}",
title,
lined_path.line_number.saturating_add(line_number.get())
absolute_line_number.saturating_add(line_number.get())
);
let line_info = format!("line {line_number}:").cyan();
println!("{absolute_line_info} {line_info} {failure}");
Expand All @@ -58,7 +65,7 @@ pub fn run(path: &PathBuf, title: &str) {
assert!(!any_failures, "Some tests failed.");
}

#[derive(PartialEq, PartialOrd, Eq, Ord, Hash)]
#[derive(PartialEq, PartialOrd, Eq, Ord)]
struct AbsoluteLineNumberPath {
path: SystemPathBuf,
line_number: OneIndexed,
Expand Down Expand Up @@ -86,15 +93,16 @@ fn run_test(test: &parser::MarkdownTest) -> Result<(), Failures> {
let mut failures = BTreeMap::default();

for numbered_path in paths {
let file = system_path_to_file(&db, numbered_path.path.clone()).unwrap();
let path = numbered_path.path.clone();
let file = system_path_to_file(&db, path.clone()).unwrap();
let parsed = parsed_module(&db, file);

// TODO allow testing against code with syntax errors
assert!(
parsed.errors().is_empty(),
"Python syntax errors in {}, {:?}: {:?}",
test.name(),
numbered_path.path,
path,
parsed.errors()
);

Expand Down

0 comments on commit 77355c6

Please sign in to comment.