Use Environment.NewLine instead of hard-coded linefeed in ParseError.ToString (#11746)

This commit is contained in:
Tyler James Leonhardt
2020-02-03 14:03:12 -08:00
committed by GitHub
parent 58d53b53fd
commit ac1b83f152
2 changed files with 21 additions and 1 deletions
@@ -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"
}
}
}