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 @@ -363,8 +363,8 @@ private string[] GenerateTableRow(string[] values, ReadOnlySpan<int> alignment,
// for a given row, walk the columns
for (int col = 0; col < scArray.Length; col++)
{
// if the column is the last column with content, we need to trim trailing whitespace
if (col == lastColWithContent[row])
// if the column is the last column with content, we need to trim trailing whitespace, unless there is only one row
if (col == lastColWithContent[row] && screenRows > 1)
{
sb.Append(scArray[col][row].TrimEnd());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,16 @@ Left Center Right
}

It "Format-Table should correctly render headers that span multiple rows: <variation>" -TestCases @(
@{ view = "Default"; widths = 7,7,7; variation = "2 row, 1 row, 1 row"; expectedTable = @"

LongLon Header2 Header3
gHeader
------- ------- -------
1 2 3



"@ },
@{ view = "Default"; widths = 4,7,4; variation = "4 row, 1 row, 2 row"; expectedTable = @"

Long Header2 Head
Expand Down Expand Up @@ -463,7 +473,7 @@ er
Write-Verbose $e.ToString() -Verbose
}
$ps.HadErrors | Should -BeFalse
$output.Replace("`r","").Replace(" ",".").Replace("`n","``") | Should -BeExactly $expectedTable.Replace("`r","").Replace(" ",".").Replace("`n","``")
$output.Replace("`r","").Replace(" ",".").Replace("`n","^") | Should -BeExactly $expectedTable.Replace("`r","").Replace(" ",".").Replace("`n","^")
}

It "Format-Table should correctly render rows: <variation>" -TestCases @(
Expand Down Expand Up @@ -668,6 +678,43 @@ er
Write-Verbose $e.ToString() -Verbose
}
$ps.HadErrors | Should -BeFalse
$output.Replace("`r","").Replace(" ","*").Replace("`n","``") | Should -BeExactly $expectedTable.Replace("`r","").Replace(" ",".").Replace("`n","``")
$output.Replace("`r","").Replace(" ","*").Replace("`n","^") | Should -BeExactly $expectedTable.Replace("`r","").Replace(" ",".").Replace("`n","^")
}

It "Should render header/row correctly where values are wider than header w/ implicit autosize: <variation>" -TestCases @(
@{ variation = "first column"; obj = [pscustomobject]@{abc="1234";bcd="123"},[pscustomobject]@{abc="1";bcd="1234"}; expectedTable = @"

abc bcd
--- ---
1234 123
1 1234



"@ },
@{ variation = "both columns"; obj = [pscustomobject]@{abc="1234";bcd="1234"},[pscustomobject]@{abc="1";bcd="1"}; expectedTable = @"

abc bcd
--- ---
1234 1234
1 1



"@ },
@{ variation = "second column"; obj = [pscustomobject]@{abc="123";bcd="1234"},[pscustomobject]@{abc="1";bcd="123"}; expectedTable = @"

abc bcd
--- ---
123 1234
1 123



"@ }
) {
param($obj, $expectedTable)
$output = $obj | Format-Table | Out-String
$output.Replace("`r","").Replace(" ",".").Replace("`n","^") | Should -BeExactly $expectedTable.Replace("`r","").Replace(" ",".").Replace("`n","^")
}
}