mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Use Environment.NewLine instead of hard-coded linefeed in ParseError.ToString (#11746)
This commit is contained in:
@@ -8059,7 +8059,7 @@ namespace System.Management.Automation.Language
|
||||
/// <returns></returns>
|
||||
public override string ToString()
|
||||
{
|
||||
return PositionUtilities.VerboseMessage(Extent) + "\n" + Message;
|
||||
return PositionUtilities.VerboseMessage(Extent) + Environment.NewLine + Message;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -459,3 +459,23 @@ Describe "Ternary Operator parsing" -Tags CI {
|
||||
$expr.IfFalse | Should -BeOfType System.Management.Automation.Language.ConstantExpressionAst
|
||||
}
|
||||
}
|
||||
|
||||
Describe "ParserError type tests" -Tag CI {
|
||||
# This test was added because there use to be a hardcoded newline in the ToString() method of
|
||||
# the ParseError class. This makes sure the proper newlines are used.
|
||||
It "Should use consistant newline depending on OS" {
|
||||
$ers = $null
|
||||
[System.Management.Automation.Language.Parser]::ParseInput('$x =', [ref]$null, [ref]$ers) | Out-Null
|
||||
$measureResult = $ers[0].ToString() -split [System.Environment]::NewLine | Measure-Object
|
||||
|
||||
# We expect the string to have 4 lines. That means that if we split by NewLine for that platform,
|
||||
# We should have 4 as the count.
|
||||
$measureResult.Count | Should -BeExactly 4
|
||||
|
||||
# Just checking the above is not enough. We should also make sure that on non-Windows, there are no
|
||||
# `r`n
|
||||
if (!$IsWindows) {
|
||||
$measureResult = $ers[0].ToString() | Should -Not -Contain "`r`n"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user