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

Assert diff swaps actual and expected when comparing multiline strings #3681

Closed
marvinhagemeister opened this issue Sep 29, 2023 · 4 comments · Fixed by #3685
Closed

Assert diff swaps actual and expected when comparing multiline strings #3681

marvinhagemeister opened this issue Sep 29, 2023 · 4 comments · Fixed by #3685
Assignees
Labels
bug Something isn't working

Comments

@marvinhagemeister
Copy link
Contributor

marvinhagemeister commented Sep 29, 2023

Describe the bug

When assertEquals is used to compare a multiline string and the check fails, then the diff output confusingly swaps the order of actual and expected.

Screenshot 2023-09-29 at 14 05 02

Steps to Reproduce

import { assertEquals } from "https://deno.land/std@0.203.0/assert/mod.ts";

Deno.test("multiline", () => {
  const actual = `<div>
  <div>
    <p>
    foo</p>
  </div>
  [object Object],barbaz</div>
</div>  
`;

  const expected = `<div>
  <div>
    <p>foo</p>
    barbaz
  </div>
</div>
`;
  assertEquals(actual, expected);
});

Expected behavior

It should not swap the order. It should mark actual as "actual" and expected as "expected".

Environment

  • OS: [e.g. Ubuntu 20.04, MacOS 11]
  • deno version: 1.37.1
  • std version: 0.203.0
@marvinhagemeister marvinhagemeister added bug Something isn't working needs triage labels Sep 29, 2023
@marvinhagemeister
Copy link
Contributor Author

Might be related #3039

@lucacasonato
Copy link
Member

Duplicate of #3039

@kt3k
Copy link
Member

kt3k commented Oct 3, 2023

It looks like this happens only when actual has more diff lines than expected. I'll look into more details.

import { assertEquals } from "https://deno.land/std@0.203.0/assert/mod.ts";
Deno.test("multiline", () => {
  assertEquals("a\na", "e"); // diff swaps
});
Deno.test("multiline", () => {
  assertEquals("a\na", "e\ne"); // diff doesn't swap
});
Deno.test("multiline", () => {
  assertEquals("a", "e\ne"); // diff doesn't swap
});

@kt3k kt3k removed the needs triage label Oct 3, 2023
@kt3k kt3k self-assigned this Oct 3, 2023
@marvinhagemeister
Copy link
Contributor Author

@kt3k From what I can tell the code uses a variant of the myers algorithm. A common optmization there is to ensure that the grid is always in portrait mode, because the algorithm searches for the biggest x value. It might just be that the code forgets to swap the insertion/deletions back to the original landscape grid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants