Fix trimming of whitespace when table is wrapped (#7184)

This commit is contained in:
Steve Lee 2018-06-26 22:24:03 -07:00 committed by Ilya
parent 7628f8819d
commit b1fbcee6d2
2 changed files with 42 additions and 5 deletions

View file

@ -294,14 +294,11 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
System.Span<int> lastColWithContent = screenRows <= OutCommandInner.StackAllocThreshold ? stackalloc int[screenRows] : new int[screenRows];
for (int row = 0; row < screenRows; row++)
{
for (int col = scArray.Length - 1; col > 0; col--)
for (int col = 0; col < scArray.Length; col++)
{
int colWidth = _si.columnInfo[validColumnArray[col]].width;
int headerLength = values[col].Length;
if (headerLength / colWidth >= row && headerLength % colWidth > 0)
if (scArray[col].Count > row)
{
lastColWithContent[row] = col;
break;
}
}
}

View file

@ -760,4 +760,44 @@ abc abc
$output = $obj | Format-Table | Out-String
$output.Replace("`r","").Replace(" ",".").Replace("`n","^") | Should -BeExactly $expectedTable.Replace("`r","").Replace(" ",".").Replace("`n","^")
}
It "Should render rows correctly when wrapped: <variation>" -TestCases @(
@{ variation = "right"; obj = [pscustomobject] @{A=1;B=2;Name="This`nIs some random`nmultiline content"}; expectedTable = @"
A B Name
- - ----
1 2 This
Is some random
multiline content
"@ },
@{ variation = "left"; obj = [pscustomobject] @{Name="This`nIs some random`nmultiline content";A=1;B=2}; expectedTable = @"
Name A B
---- - -
This 1 2
Is some random
multiline content
"@ },
@{ variation = "middle"; obj = [pscustomobject] @{A=1;Name="This`nIs some random`nmultiline content";B=2}; expectedTable = @"
A Name B
- ---- -
1 This 2
Is some random
multiline content
"@ }
) {
param($obj, $expectedTable)
$output = $obj | Format-Table -Wrap | Out-String
$output.Replace("`r","").Replace(" ",".").Replace("`n","^") | Should -BeExactly $expectedTable.Replace("`r","").Replace(" ",".").Replace("`n","^")
}
}