Fix Format-Table -RepeatHeader for property derived tables (#18870)

This commit is contained in:
Steve Lee
2022-12-31 12:00:00 +05:00
committed by GitHub
parent a581e36419
commit f04940b76c
2 changed files with 9 additions and 0 deletions
@@ -223,6 +223,7 @@ namespace Microsoft.PowerShell.Commands.Internal.Format
TableHeaderInfo thi = new TableHeaderInfo();
thi.hideHeader = this.HideHeaders;
thi.repeatHeader = this.RepeatHeader;
for (int k = 0; k < this.activeAssociationList.Count; k++)
{
@@ -813,6 +813,14 @@ A Name B
($lines | Select-String "Name\s*Value").Count | Should -Be ($numHeaders + 1)
}
It "-RepeatHeader should output the header at every screen full for custom table" -Skip:([Console]::WindowHeight -eq 0) {
$numHeaders = 4
$numObjects = [Console]::WindowHeight * $numHeaders
$out = 1..$numObjects | ForEach-Object { [pscustomobject]@{foo=$_;bar=$_;hello=$_;world=$_} } | Format-Table -Property hello, world -RepeatHeader | Out-String
$lines = $out.Split([System.Environment]::NewLine)
($lines | Select-String "Hello\s*World").Count | Should -Be ($numHeaders + 1)
}
It "Should be formatted correctly if width is declared and using center alignment" {
$expectedTable = @"