Simplify Rust test newline handling

This commit is contained in:
George Thomas 2025-12-23 11:31:22 +00:00
parent 4c05c068fa
commit 1d552fab86

View File

@ -19,9 +19,9 @@ fn main() {
let input = fs::read_to_string(format!("../inputs/{}/{}", t, puzzle.number())) let input = fs::read_to_string(format!("../inputs/{}/{}", t, puzzle.number()))
.expect("no input file"); .expect("no input file");
puzzle.with_parts(&input, &|n, run| { puzzle.with_parts(&input, &|n, run| {
let expected = let expected = fs::read_to_string(format!("../outputs/{}/{}/{}", t, puzzle.number(), n))
fs::read_to_string(format!("../outputs/{}/{}/{}", t, puzzle.number(), n))
.expect("no golden file"); .expect("no golden file");
let expected = expected.trim_end();
print!(" {}: ", n); print!(" {}: ", n);
let start = Instant::now(); let start = Instant::now();
let output = run(); let output = run();
@ -35,8 +35,8 @@ fn main() {
} else { } else {
println!( println!(
"expected {}, got {}", "expected {}, got {}",
expected.trim_end(), expected,
output.trim_end() output
); );
}; };
}); });
@ -55,7 +55,7 @@ impl<Input, const N: usize> SomePuzzle for Puzzle<Input, { N }> {
fn with_parts(&self, s: &str, f: &dyn Fn(usize, &dyn Fn() -> String)) { fn with_parts(&self, s: &str, f: &dyn Fn(usize, &dyn Fn() -> String)) {
let input = (self.parser)(s); let input = (self.parser)(s);
for (i, p) in self.parts.iter().enumerate() { for (i, p) in self.parts.iter().enumerate() {
f(i + 1, &|| p(&input) + "\n"); f(i + 1, &|| p(&input));
} }
} }
} }