Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -294,14 +294,11 @@ private string[] GenerateTableRow(string[] values, ReadOnlySpan<int> alignment,
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;
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 empty lines (here and in 2 other cases below) - are they necessary ?

Copy link
Member Author

@SteveL-MSFT SteveL-MSFT Jun 26, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It annoys me, too, but that is currently what PowerShell outputs. We should probably look into that as a separate issue. Created #7186



"@ },
@{ 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","^")
}
}