Skip to content

Assert.AreEqual string: consider replacing whitespaces by a symbol #6716

Closed

Description

Describe the bug

When reviewing diffs for Assert.AreEqual of strings, it's sometimes uneasy to understand how many spaces there are. Let's take:

Assert.AreEqual failed. Expected string length 199 but was 139. 'expected' expression: 'Normalize(expected)', 'actual' expression: 'Normalize(actual)'.
Expected: "...n 1; }␊    #endregion␊␊    #region ..."
But was:  "...n 1; }␊    #endregion␊    #endregion␊}"

Expected behavior

Space is replaced with a symbol:

  • ␣ - Space (U+2423 OPEN BOX)
  • · - Middle dot

Nit: if that's not already handled, also consider replacing tabs:

→ - Tab (can also use ⇥ or ␉)

Activity

  1. added
    area/assertion
    on Oct 10, 2025
  2. nohwnd commented on Oct 10, 2025

    @nohwnd
    Member

    Since v4 we replace common formatting characters with their visible version. Except for spaces and tabs. We don't control how they are rendered, we just change the character to visible.

    Space is not replaced because it impacts readability of longer text when spaces are not the difference.

    Tab is not replaced because it would break formatting of text. But in this case it probably does not matter as much since it is 1 line only.

    We do however have the indicator of where the difference is, which should make it even more obvious where the difference is.

    Image
  3. Youssef1313 commented on Oct 12, 2025

    @Youssef1313
    Member

    I think we could have a heuristic here specific to multi-line diffing, similar to how the diffing from Roslyn testing library works. I think Roslyn testing uses https://github.com/mmanela/diffplex. I'm not sure how feasible it is to add such extra dependency to MSTest. Or alternatively, we copy the needed parts from DiffPlex with license notice (we might want to confirm with CELA about the licensing stuff and whether we can copy from DiffPlex).

    We might even consider if DiffPlex provides good diffing for single-line and use that instead.

  4. Youssef1313 commented on Nov 1, 2025

    @Youssef1313
    Member

    Related: #6771

  5. Evangelink commented on May 15, 2026

    @Evangelink
    MemberAuthor

    It won't be necessary with the new format, so closing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/assertion

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions