Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Newlines-only diff are inconsistently reported #28

Open
elinorbgr opened this issue Feb 27, 2018 · 1 comment
Open

Newlines-only diff are inconsistently reported #28

elinorbgr opened this issue Feb 27, 2018 · 1 comment

Comments

@elinorbgr
Copy link

Consider this example:

fn main() {
    let input = r#"
Foo
Bar


Baz

Bam


Meh
"#;

    let output = r#"
Foo
Bar

Baz
Bam

Meh"#;

    let changeset = Changeset::new(input, output, "\n");
    println!("distance = {}", changeset.distance);
    println!("{:#?}", changeset.diffs);
}

It outputs this:

distance = 4
[
    Same(
        "Foo\nBar\n\nBaz\nBam\n\nMeh\n"
    )
]

There is an inconsistency here, there is a distance of 4 yet the diff is only a single Same entry.

I would typically have expected the diff to be something like:

[
    Same("Foo\nBar\n"),
    Rem("\n"),
    Same("Baz\n"),
    Rem("\n"),
    Same("Bam\n"),
    Rem("\n"),
    Same("Meh"),
    Rem("\n")
]
@Rulexec
Copy link

Rulexec commented Apr 27, 2024

Same problem. I have strings count: 0 and count: 0\n, receiving distance = 1 and:

[
    Same(
        "count: 0\n",
    ),
]

UPD: solved it by following hack:

let (distance, diffs) = diff(expected, actual, "\n");

let (distance, diffs) = if distance != 0 && diffs.len() == 1 {
    diff(expected, actual, "")
} else {
    (distance, diffs)
};

And then added hack for formatting diffs, which checks for strings equal to "\n", which can happen only in this case and not printing them, so output will be:

    count: 0
  + 

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants