Skip to content

Commit

Permalink
Strip \r character on integration_test.rs
Browse files Browse the repository at this point in the history
  • Loading branch information
AngheloAlf committed Aug 14, 2024
1 parent 4228a7b commit fc0c907
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions slinky/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,37 +7,49 @@ use std::path::{Path, PathBuf};
use rstest::rstest;
use slinky::{RuntimeSettings, ScriptExporter, ScriptImporter, SlinkyError};

fn compare_multiline_strings(left: &str, right: &str) {
if left == right {
fn compare_multiline_strings(expected: &str, generated: &str) {
// We manually strip the CARRIAGE RETURN (`\r`/`U+000D`) character only from
// expected because it may get included into the test files when cloning this
// repository on Windows with a git configured with its default settings.
//
// Rust never writes a `\r` character using the `writeln!` macro, so it is
// not like this character would get added automatically on Windows builds
// of slinky, so the simplest solution is to just strip this character from
// `expected`.
//
// What can go wrong?
let expected_cleaned = expected.replace('\r', "");

if expected_cleaned == generated {
return;
}

// both strings are not the same, try to figure out where the issue is.
println!("Not equal strings :c");
println!();

let mut left_splitted = left.split("\n");
let mut right_splitted = right.split("\n");
let mut expected_splitted = expected_cleaned.split("\n");
let mut generated_splitted = generated.split("\n");

// https://stackoverflow.com/a/38168890/6292472
loop {
match (left_splitted.next(), right_splitted.next()) {
match (expected_splitted.next(), generated_splitted.next()) {
(Some(l), Some(r)) => {
if l != r {
println!(" Different lines:");
println!(" left: {:?}", l);
println!(" right: {:?}", r);
println!(" expected: {:?}", l);
println!(" generated: {:?}", r);
println!();
}
}
(Some(l), None) => {
println!(" Only one line:");
println!(" left: {:?}", l);
println!(" expected: {:?}", l);
println!();
}
(None, Some(r)) => {
println!(" Only one line:");
println!(" right: {:?}", r);
println!(" generated: {:?}", r);
println!();
}
(None, None) => break,
Expand All @@ -48,7 +60,7 @@ fn compare_multiline_strings(left: &str, right: &str) {
println!("full inequality:");
println!();

assert_eq!(left, right);
assert_eq!(expected_cleaned, generated);
}

fn create_runtime_settings() -> RuntimeSettings {
Expand Down

0 comments on commit fc0c907

Please sign in to comment.