GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Add tests for Format-Table -Wrap (#6670) · PowerShell/PowerShell@2da7576

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
  • test/powershell/Modules/Microsoft.PowerShell.Utility
    • Format-Table.Tests.ps1
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1‎

Copy file name to clipboardExpand all lines: test/powershell/Modules/Microsoft.PowerShell.Utility/Format-Table.Tests.ps1
+206-1Lines changed: 206 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,4 +465,209 @@ er
465465
$ps.HadErrors | Should -BeFalse
466466
$output.Replace("`r","").Replace(" ",".").Replace("`n","``") | Should -BeExactly $expectedTable.Replace("`r","").Replace(" ",".").Replace("`n","``")
467467
}
468-
}
468+
469+
It "Format-Table should correctly render rows: <variation>" -TestCases @(
470+
@{ view = "Default"; widths = 4,7,5; variation = "narrow values"; values = [PSCustomObject]@{First=1;Second=2;Third=3}; wrap = $false; expectedTable = @"
471+
472+
Long*Header2*Heade
473+
Long*********r3
474+
Head
475+
er
476+
----*-------*-----
477+
1**********2***3
478+
479+
480+
481+
"@ },
482+
@{ view = "Default"; widths = 4,7,5; variation = "narrow values with wrap"; values = [PSCustomObject]@{First=1;Second=2;Third=3}; wrap = $true; expectedTable = @"
483+
484+
Long*Header2*Heade
485+
Long*********r3
486+
Head
487+
er
488+
----*-------*-----
489+
1**********2*3
490+
491+
492+
493+
"@ },
494+
@{ view = "Default"; widths = 4,7,5; variation = "wide values"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $false; expectedTable = @"
495+
496+
Long*Header2*Heade
497+
Long*********r3
498+
Head
499+
er
500+
----*-------*-----
501+
1...*...5678*12...
502+
503+
504+
505+
"@ },
506+
@{ view = "One"; widths = 3,1,1; variation = "wide values, 1 column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $false; expectedTable = @"
507+
508+
Lon
509+
gLo
510+
ngH
511+
ead
512+
er
513+
---
514+
123
515+
516+
517+
518+
"@ },
519+
@{ view = "Default"; widths = 4,8,6; variation = "wide values with wrap, 1st column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @"
520+
521+
Long**Header2*Header
522+
Long**********3
523+
Head
524+
er
525+
----**-------*------
526+
1234*12345678*123456
527+
5
528+
529+
530+
531+
"@ },
532+
@{ view = "Default"; widths = 5,7,6; variation = "wide values with wrap, 2nd column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @"
533+
534+
LongL*Header2*Header
535+
ongHe*********3
536+
ader
537+
-----*-------*------
538+
12345*1234567*123456
539+
************8
540+
541+
542+
543+
"@ },
544+
@{ view = "Default"; widths = 5,8,5; variation = "wide values with wrap, 3rd column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @"
545+
546+
LongL**Header2*Heade
547+
ongHe**********r3
548+
ader
549+
-----**-------*-----
550+
12345*12345678*12345
551+
***************6
552+
553+
554+
555+
"@ },
556+
@{ 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 = @"
557+
558+
Long*Header2*Heade
559+
Long*********r3
560+
Head
561+
er
562+
----*-------*-----
563+
1234*1234567*12345
564+
5**********8*6
565+
566+
567+
568+
"@ },
569+
@{ view = "One"; widths = 3,1,1; variation = "wide values with wrap, with 1 column"; values = [PSCustomObject]@{First="12345";Second="12345678";Third="123456"}; wrap = $true; expectedTable = @"
570+
571+
Lon
572+
gLo
573+
ngH
574+
ead
575+
er
576+
---
577+
123
578+
45
579+
580+
581+
582+
"@ }
583+
) {
584+
param($view, $widths, $values, $wrap, $expectedTable)
585+
$ps1xml = @"
586+
<Configuration>
587+
<ViewDefinitions>
588+
<View>
589+
<Name>Default</Name>
590+
<ViewSelectedBy>
591+
<TypeName>Test.Format</TypeName>
592+
</ViewSelectedBy>
593+
<TableControl>
594+
<TableHeaders>
595+
<TableColumnHeader>
596+
<Alignment>left</Alignment>
597+
<Label>LongLongHeader</Label>
598+
<Width>{0}</Width>
599+
</TableColumnHeader>
600+
<TableColumnHeader>
601+
<Alignment>right</Alignment>
602+
<Label>Header2</Label>
603+
<Width>{1}</Width>
604+
</TableColumnHeader>
605+
<TableColumnHeader>
606+
<Alignment>center</Alignment>
607+
<Label>Header3</Label>
608+
<Width>{2}</Width>
609+
</TableColumnHeader>
610+
</TableHeaders>
611+
<TableRowEntries>
612+
<TableRowEntry>
613+
<TableColumnItems>
614+
<TableColumnItem>
615+
<PropertyName>First</PropertyName>
616+
</TableColumnItem>
617+
<TableColumnItem>
618+
<PropertyName>Second</PropertyName>
619+
</TableColumnItem>
620+
<TableColumnItem>
621+
<PropertyName>Third</PropertyName>
622+
</TableColumnItem>
623+
</TableColumnItems>
624+
</TableRowEntry>
625+
</TableRowEntries>
626+
</TableControl>
627+
</View>
628+
<View>
629+
<Name>One</Name>
630+
<ViewSelectedBy>
631+
<TypeName>Test.Format</TypeName>
632+
</ViewSelectedBy>
633+
<TableControl>
634+
<TableHeaders>
635+
<TableColumnHeader>
636+
<Label>LongLongHeader</Label>
637+
<Width>{0}</Width>
638+
</TableColumnHeader>
639+
</TableHeaders>
640+
<TableRowEntries>
641+
<TableRowEntry>
642+
<TableColumnItems>
643+
<TableColumnItem>
644+
<PropertyName>First</PropertyName>
645+
</TableColumnItem>
646+
</TableColumnItems>
647+
</TableRowEntry>
648+
</TableRowEntries>
649+
</TableControl>
650+
</View>
651+
</ViewDefinitions>
652+
</Configuration>
653+
"@
654+
$ps1xml = $ps1xml.Replace("{0}", $widths[0]).Replace("{1}", $widths[1]).Replace("{2}", $widths[2])
655+
$ps1xmlPath = Join-Path -Path $TestDrive -ChildPath "test.format.ps1xml"
656+
Set-Content -Path $ps1xmlPath -Value $ps1xml
657+
# run in own runspace so not affect global sessionstate
658+
$ps = [powershell]::Create()
659+
$ps.AddScript( {
660+
param($ps1xmlPath, $view, $values, $wrap)
661+
Update-FormatData -AppendPath $ps1xmlPath
662+
$values.PSObject.TypeNames.Insert(0,"Test.Format")
663+
$values | Format-Table -View $view -Wrap:$wrap | Out-String
664+
} ).AddArgument($ps1xmlPath).AddArgument($view).AddArgument($values).AddArgument($wrap) | Out-Null
665+
$output = $ps.Invoke()
666+
foreach ($e in $ps.Streams.Error)
667+
{
668+
Write-Verbose $e.ToString() -Verbose
669+
}
670+
$ps.HadErrors | Should -BeFalse
671+
$output.Replace("`r","").Replace(" ","*").Replace("`n","``") | Should -BeExactly $expectedTable.Replace("`r","").Replace(" ",".").Replace("`n","``")
672+
}
673+
}

0 commit comments

Comments
0 (0)
You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.