Skip to content

Improve Should-BeString to show string diff with arrow marker#2731

Merged
nohwnd merged 3 commits into
mainfrom
fix/2462-should-bestring
Jun 18, 2026
Merged

Improve Should-BeString to show string diff with arrow marker#2731
nohwnd merged 3 commits into
mainfrom
fix/2462-should-bestring

Conversation

@nohwnd

@nohwnd nohwnd commented Jun 17, 2026

Copy link
Copy Markdown
Member

Fixes #2462

When Should-BeString fails, the error message now shows:

  • The difference index
  • String lengths (when different)
  • Expected and actual strings with expanded special characters (\n, \r, \t, etc.)
  • An arrow marker pointing to the first difference

Before:

Expected [string] 'abc', but got [string] 'bde'.

After:

Expected strings to be the same, but they were different.
String lengths are both 3.
Strings differ at index 0.
Expected: 'abc'
But was:  'bde'
          ^

Whitespace differences are visible even without -IgnoreWhitespace:

Expected strings to be the same, but they were different.
Expected length: 8
Actual length:   7
Strings differ at index 3.
Expected: 'abc\r\ndef'
But was:  'abc\ndef'
          ----^

nohwnd and others added 3 commits June 17, 2026 16:15
When strings differ, show the difference index, expanded special
characters (e.g. \n, \r, \t), and an arrow pointing to the first
difference — matching the style of Should -Be.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Verify arrow position precisely using Verify-Equal with here-strings
instead of Verify-Like wildcards. Add test for mid-string difference
showing dashes before the arrow marker.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
Use explicit LF in Get-StringDifferenceMessage and normalize
expected values in tests with -replace to match on all platforms.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
@nohwnd nohwnd merged commit 18c2758 into main Jun 18, 2026
13 checks passed
@nohwnd nohwnd deleted the fix/2462-should-bestring branch June 18, 2026 11:23
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

Successfully merging this pull request may close these issues.

Improve Should-BeString assertion

1 participant