Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/functions/assertions/Be.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ function Expand-SpecialCharacters {
[AllowEmptyString()]
[string[]]$InputObject)
process {
$InputObject -replace "`n", "\n" -replace "`r", "\r" -replace "`t", "\t" -replace "`0", "\0" -replace "`b", "\b"
[Pester.Formatter]::EscapeControlChars($InputObject)
}
}

Expand Down
12 changes: 3 additions & 9 deletions tst/functions/assert/String/Should-BeString.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,8 @@ But was: 'abc'

It "Shows expanded whitespace characters in diff" {
$err = { "abc`ndef" | Should-BeString "abc`r`ndef" } | Verify-AssertionFailed
$err.Exception.Message | Verify-Equal (@'
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'
----^
'@ -replace "`r`n", "`n")
$cr = [char]0x240D
$lf = [char]0x240A
$err.Exception.Message | Verify-Equal ("Expected strings to be the same, but they were different.`nExpected length: 8`nActual length: 7`nStrings differ at index 3.`nExpected: 'abc${cr}${lf}def'`nBut was: 'abc${lf}def'`n ---^" -replace "`r`n", "`n")
}
}
6 changes: 3 additions & 3 deletions tst/functions/assertions/Be.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,15 @@ InPesterModuleScope {
}

It "Replaces non-printable characters correctly" {
ShouldBeFailureMessage "`n`r`b`0`tx" "`n`r`b`0`ty" | Verify-Equal "Expected strings to be the same, but they were different.`nString lengths are both 6.`nStrings differ at index 5.`nExpected: '\n\r\b\0\ty'`nBut was: '\n\r\b\0\tx'`n ----------^"
ShouldBeFailureMessage "`n`r`b`0`tx" "`n`r`b`0`ty" | Verify-Equal "Expected strings to be the same, but they were different.`nString lengths are both 6.`nStrings differ at index 5.`nExpected: '$(([char]0x240A))$(([char]0x240D))$(([char]0x2408))$(([char]0x2400))$(([char]0x2409))y'`nBut was: '$(([char]0x240A))$(([char]0x240D))$(([char]0x2408))$(([char]0x2400))$(([char]0x2409))x'`n -----^"
}

It "The arrow points to the correct position when non-printable characters are replaced before the difference" {
ShouldBeFailureMessage "123`n456" "123`n789" | Verify-Equal "Expected strings to be the same, but they were different.`nString lengths are both 7.`nStrings differ at index 4.`nExpected: '123\n789'`nBut was: '123\n456'`n -----^"
ShouldBeFailureMessage "123`n456" "123`n789" | Verify-Equal "Expected strings to be the same, but they were different.`nString lengths are both 7.`nStrings differ at index 4.`nExpected: '123$(([char]0x240A))789'`nBut was: '123$(([char]0x240A))456'`n ----^"
}

It "The arrow points to the correct position when non-printable characters are replaced after the difference" {
ShouldBeFailureMessage "abcd`n123" "abc!`n123" | Verify-Equal "Expected strings to be the same, but they were different.`nString lengths are both 8.`nStrings differ at index 3.`nExpected: 'abc!\n123'`nBut was: 'abcd\n123'`n ---^"
ShouldBeFailureMessage "abcd`n123" "abc!`n123" | Verify-Equal "Expected strings to be the same, but they were different.`nString lengths are both 8.`nStrings differ at index 3.`nExpected: 'abc!$(([char]0x240A))123'`nBut was: 'abcd$(([char]0x240A))123'`n ---^"
}
}
}
Expand Down
Loading