Fix formatting of header of table when center aligned (#8497)

This commit is contained in:
Steve Lee
2018-12-22 12:57:44 +05:00
committed by Ilya
parent 140a66ca73
commit 2eb7ca8309
2 changed files with 24 additions and 11 deletions
@@ -386,7 +386,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
{
StringCollection sc = StringManipulationHelper.GenerateLines(dc, val,
_si.columnInfo[k].width, _si.columnInfo[k].width);
if (addPadding || alignment == TextAlignment.Right)
if (addPadding || alignment == TextAlignment.Right || alignment == TextAlignment.Center)
{
// if length is shorter, do some padding
for (int col = 0; col < sc.Count; col++)
@@ -476,7 +476,7 @@ er
@{ view = "Default"; widths = 4,7,5; variation = "narrow values"; values = [PSCustomObject]@{First=1;Second=2;Third=3}; wrap = $false; expectedTable = @"
Long*Header2*Heade
Long*********r3
Long**********r3
Head
er
----*-------*-----
@@ -487,18 +487,18 @@ er
@{ view = "Default"; widths = 4,7,5; variation = "narrow values with wrap"; values = [PSCustomObject]@{First=1;Second=2;Third=3}; wrap = $true; expectedTable = @"
Long*Header2*Heade
Long*********r3
Long**********r3
Head
er
----*-------*-----
1**********2*3
1**********2***3
"@ },
@{ view = "Default"; widths = 4,7,5; variation = "wide values"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $false; expectedTable = @"
Long*Header2*Heade
Long*********r3
Long**********r3
Head
er
----*-------*-----
@@ -521,7 +521,7 @@ er
@{ view = "Default"; widths = 4,8,6; variation = "wide values with wrap, 1st column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @"
Long**Header2*Header
Long**********3
Long************3
Head
er
----**-------*------
@@ -533,7 +533,7 @@ er
@{ view = "Default"; widths = 5,7,6; variation = "wide values with wrap, 2nd column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @"
LongL*Header2*Header
ongHe*********3
ongHe***********3
ader
-----*-------*------
12345*1234567*123456
@@ -544,23 +544,23 @@ ader
@{ view = "Default"; widths = 5,8,5; variation = "wide values with wrap, 3rd column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @"
LongL**Header2*Heade
ongHe**********r3
ongHe***********r3
ader
-----**-------*-----
12345*12345678*12345
***************6
*****************6
"@ },
@{ view = "Default"; widths = 4,7,5; variation = "wide values with wrap, all 3 columns"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @"
Long*Header2*Heade
Long*********r3
Long**********r3
Head
er
----*-------*-----
1234*1234567*12345
5**********8*6
5**********8***6
"@ },
@@ -799,4 +799,17 @@ A Name B
$lines = $out.Split([System.Environment]::NewLine)
($lines | Select-String "Name\s*Value").Count | Should -Be ($numHeaders + 1)
}
It "Should be formatted correctly if width is declared and using center alignment" {
$expectedTable = @"
one
---
1
"@
$output = [pscustomobject] @{ one = 1 } | Format-Table @{ l='one'; e='one'; width=10; alignment='center' } | Out-String
$output.Replace("`r","").Replace(" ",".").Replace("`n","^") | Should -BeExactly $expectedTable.Replace("`r","").Replace(" ",".").Replace("`n","^")
}
}