From ac8a9245be928b095a5b97baf5778b520b0ce8ba Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Mon, 10 Aug 2026 21:32:51 +0200 Subject: [PATCH] Rename -NormalizeNewline to -NormalizeLineEnding on Should-BeString and Should-NotBeString MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -NormalizeLineEnding is the more generic and correct name, it normalizes \r\n, \r and the Unicode line separator, not just \n. Renaming now while it is only in 6.1.0-rc1 avoids shipping the less accurate name in a stable release. Fixes #2967 🤖 --- src/functions/assert/String/Should-BeString.ps1 | 10 +++++----- src/functions/assert/String/Should-NotBeString.ps1 | 6 +++--- tst/functions/assert/String/Should-BeString.Tests.ps1 | 10 +++++----- .../assert/String/Should-NotBeString.Tests.ps1 | 4 ++-- 4 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/functions/assert/String/Should-BeString.ps1 b/src/functions/assert/String/Should-BeString.ps1 index 296c868a6..ae5d087c1 100644 --- a/src/functions/assert/String/Should-BeString.ps1 +++ b/src/functions/assert/String/Should-BeString.ps1 @@ -5,14 +5,14 @@ [switch]$CaseSensitive, [switch]$IgnoreWhitespace, [switch]$TrimWhitespace, - [switch]$NormalizeNewline + [switch]$NormalizeLineEnding ) if ($Actual -isnot [string]) { return $false } - if ($NormalizeNewline) { + if ($NormalizeLineEnding) { $Expected = $Expected -replace '\r\n|\r|\p{Zl}', "`n" $Actual = $Actual -replace '\r\n|\r|\p{Zl}', "`n" } @@ -58,7 +58,7 @@ function Should-BeString { .PARAMETER TrimWhitespace Trims whitespace at the start and end of the string. - .PARAMETER NormalizeNewline + .PARAMETER NormalizeLineEnding Normalizes line endings before comparison, so that `\r\n`, `\r`, and the Unicode line separator are all treated as `\n`. Use this to compare multi-line strings across platforms without failing on line-ending style. Unlike `-IgnoreWhitespace`, the newlines and their positions are kept, so indentation and blank lines are still compared. .PARAMETER Because @@ -110,13 +110,13 @@ function Should-BeString { [switch]$CaseSensitive, [switch]$IgnoreWhitespace, [switch]$TrimWhitespace, - [switch]$NormalizeNewline + [switch]$NormalizeLineEnding ) $assert = New-ShouldAssertion -Caller $PSCmdlet -Actual $Actual -Buffer $local:Input $Actual = $assert.Actual() - $stringsAreEqual = Test-StringEqual -Expected $Expected -Actual $Actual -CaseSensitive:$CaseSensitive -IgnoreWhitespace:$IgnoreWhiteSpace -TrimWhitespace:$TrimWhitespace -NormalizeNewline:$NormalizeNewline + $stringsAreEqual = Test-StringEqual -Expected $Expected -Actual $Actual -CaseSensitive:$CaseSensitive -IgnoreWhitespace:$IgnoreWhiteSpace -TrimWhitespace:$TrimWhitespace -NormalizeLineEnding:$NormalizeLineEnding if (-not ($stringsAreEqual)) { if ($Actual -is [string]) { $assert.Fail((Get-StringDifferenceMessage -Expected $Expected -Actual $Actual -CaseSensitive:$CaseSensitive -Because $Because)) diff --git a/src/functions/assert/String/Should-NotBeString.ps1 b/src/functions/assert/String/Should-NotBeString.ps1 index c375de31a..9aa32686c 100644 --- a/src/functions/assert/String/Should-NotBeString.ps1 +++ b/src/functions/assert/String/Should-NotBeString.ps1 @@ -25,7 +25,7 @@ function Should-NotBeString { .PARAMETER TrimWhitespace Trims whitespace at the start and end of the string. - .PARAMETER NormalizeNewline + .PARAMETER NormalizeLineEnding Normalizes line endings before comparison, so that `\r\n`, `\r`, and the Unicode line separator are all treated as `\n`. Use this to compare multi-line strings across platforms without failing on line-ending style. Unlike `-IgnoreWhitespace`, the newlines and their positions are kept, so indentation and blank lines are still compared. .PARAMETER Because @@ -69,7 +69,7 @@ function Should-NotBeString { [switch]$CaseSensitive, [switch]$IgnoreWhitespace, [switch]$TrimWhitespace, - [switch]$NormalizeNewline + [switch]$NormalizeLineEnding ) $assert = New-ShouldAssertion -Caller $PSCmdlet -Actual $Actual -Buffer $local:Input @@ -79,7 +79,7 @@ function Should-NotBeString { throw [ArgumentException]"Actual is expected to be string, to avoid confusing behavior that -ne operator exhibits with collections. To assert on collections use Should-Any, Should-All or some other collection assertion." } - if (Test-StringEqual -Expected $Expected -Actual $Actual -CaseSensitive:$CaseSensitive -IgnoreWhitespace:$IgnoreWhiteSpace -TrimWhitespace:$TrimWhitespace -NormalizeNewline:$NormalizeNewline) { + if (Test-StringEqual -Expected $Expected -Actual $Actual -CaseSensitive:$CaseSensitive -IgnoreWhitespace:$IgnoreWhiteSpace -TrimWhitespace:$TrimWhitespace -NormalizeLineEnding:$NormalizeLineEnding) { if (-not $CustomMessage) { $formattedMessage = Get-StringNotEqualDefaultFailureMessage -Expected $Expected -Actual $Actual } diff --git a/tst/functions/assert/String/Should-BeString.Tests.ps1 b/tst/functions/assert/String/Should-BeString.Tests.ps1 index 0052c750c..20de40438 100644 --- a/tst/functions/assert/String/Should-BeString.Tests.ps1 +++ b/tst/functions/assert/String/Should-BeString.Tests.ps1 @@ -69,15 +69,15 @@ InPesterModuleScope { @{ l = "a`r`nb"; r = "a`rb"; lName = "CRLF"; rName = "CR" }, @{ l = "a$([char]0x2028)b"; r = "a`nb"; lName = "LS"; rName = "LF" } ) { - Test-StringEqual -Expected $l -Actual $r -NormalizeNewline | Verify-True + Test-StringEqual -Expected $l -Actual $r -NormalizeLineEnding | Verify-True } It "strings that differ in more than line ending style are not equal" { - Test-StringEqual -Expected "a`r`nb" -Actual "a`nc" -NormalizeNewline | Verify-False + Test-StringEqual -Expected "a`r`nb" -Actual "a`nc" -NormalizeLineEnding | Verify-False } It "keeps newline positions, so extra blank lines still differ" { - Test-StringEqual -Expected "a`r`nb" -Actual "a`r`n`r`nb" -NormalizeNewline | Verify-False + Test-StringEqual -Expected "a`r`nb" -Actual "a`r`n`r`nb" -NormalizeLineEnding | Verify-False } } } @@ -162,11 +162,11 @@ But was: 'abc' } It "Can compare multi-line strings ignoring line ending style" { - "line1`nline2" | Should-BeString -Expected "line1`r`nline2" -NormalizeNewline + "line1`nline2" | Should-BeString -Expected "line1`r`nline2" -NormalizeLineEnding } It "Normalizing newlines still compares indentation and blank lines" { - { "a`nb" | Should-BeString -Expected "a`n`nb" -NormalizeNewline } | Verify-AssertionFailed + { "a`nb" | Should-BeString -Expected "a`n`nb" -NormalizeLineEnding } | Verify-AssertionFailed } } diff --git a/tst/functions/assert/String/Should-NotBeString.Tests.ps1 b/tst/functions/assert/String/Should-NotBeString.Tests.ps1 index 489b26715..bdc356cb4 100644 --- a/tst/functions/assert/String/Should-NotBeString.Tests.ps1 +++ b/tst/functions/assert/String/Should-NotBeString.Tests.ps1 @@ -60,11 +60,11 @@ Describe "Should-NotBeString" { } It "Fails when strings differ only in line ending style" { - { "line1`nline2" | Should-NotBeString -Expected "line1`r`nline2" -NormalizeNewline } | Verify-AssertionFailed + { "line1`nline2" | Should-NotBeString -Expected "line1`r`nline2" -NormalizeLineEnding } | Verify-AssertionFailed } It "Passes when strings differ in more than line ending style" { - "a`nb" | Should-NotBeString -Expected "a`n`nb" -NormalizeNewline + "a`nb" | Should-NotBeString -Expected "a`n`nb" -NormalizeLineEnding } }