-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c91dd83
commit 8f3e8ea
Showing
22 changed files
with
529 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
PwshSpectreConsole.Tests/@snapshots/Format-SpectreAligned.snapshot.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[38;5;12m╭──────────────────────────────────────────────────────────────────────────────╮[0m | ||
[38;5;12m│[0m [38;5;12m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m | ||
[38;5;12m│[0m testing panel [38;5;12m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m | ||
[38;5;12m╰──────────────────────────────────────────────────────────────────────────────╯[0m |
3 changes: 3 additions & 0 deletions
3
PwshSpectreConsole.Tests/@snapshots/Format-SpectreColumns.Expanded.snapshot.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[38;5;12m╭──────╮[0m [38;5;12m╭────────╮[0m [38;5;12m╭───────╮[0m | ||
[38;5;12m│[0m left [38;5;12m│[0m [38;5;12m│[0m middle [38;5;12m│[0m [38;5;12m│[0m right [38;5;12m│[0m | ||
[38;5;12m╰──────╯[0m [38;5;12m╰────────╯[0m [38;5;12m╰───────╯[0m |
7 changes: 7 additions & 0 deletions
7
PwshSpectreConsole.Tests/@snapshots/Format-SpectreException.CustomStyles.snapshot.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[38;5;15mParameterBindingException[0m: [38;5;9mA parameter cannot be found that matches parameter [0m | ||
[38;5;9mname 'BadParam'.[0m | ||
[38;5;8mat[0m [38;5;145mvoid[0m [38;5;175mCheckActionPreference[0m[38;2;255;0;0m([0m[38;5;145mFunctionContext[0m [38;5;7mfuncContext[0m, [38;5;145mException[0m [38;5;7mexception[0m | ||
[38;2;255;0;0m)[0m | ||
[38;5;8mat[0m [38;5;145mint[0m [38;5;175mRun[0m[38;2;255;0;0m([0m[38;5;145mInterpretedFrame[0m [38;5;7mframe[0m[38;2;255;0;0m)[0m | ||
[38;5;8mat[0m [38;5;145mint[0m [38;5;175mRun[0m[38;2;255;0;0m([0m[38;5;145mInterpretedFrame[0m [38;5;7mframe[0m[38;2;255;0;0m)[0m | ||
[38;5;8mat[0m [38;5;145mint[0m [38;5;175mRun[0m[38;2;255;0;0m([0m[38;5;145mInterpretedFrame[0m [38;5;7mframe[0m[38;2;255;0;0m)[0m |
7 changes: 7 additions & 0 deletions
7
PwshSpectreConsole.Tests/@snapshots/Format-SpectreException.snapshot.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
[38;5;15mParameterBindingException[0m: [38;5;9mA parameter cannot be found that matches parameter [0m | ||
[38;5;9mname 'BadParam'.[0m | ||
[38;5;8mat[0m [38;5;145mvoid[0m [38;5;175mCheckActionPreference[0m[38;5;8m([0m[38;5;145mFunctionContext[0m [38;5;8mfuncContext[0m, [38;5;145mException[0m [38;5;8mexception[0m | ||
[38;5;8m)[0m | ||
[38;5;8mat[0m [38;5;145mint[0m [38;5;175mRun[0m[38;5;8m([0m[38;5;145mInterpretedFrame[0m [38;5;8mframe)[0m | ||
[38;5;8mat[0m [38;5;145mint[0m [38;5;175mRun[0m[38;5;8m([0m[38;5;145mInterpretedFrame[0m [38;5;8mframe)[0m | ||
[38;5;8mat[0m [38;5;145mint[0m [38;5;175mRun[0m[38;5;8m([0m[38;5;145mInterpretedFrame[0m [38;5;8mframe)[0m |
8 changes: 8 additions & 0 deletions
8
PwshSpectreConsole.Tests/@snapshots/Format-SpectreGrid.snapshot.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
Row 1, Col 1 Row 1, Col 2 Row 1, Col Row 1, Col Row 1, Col Row 1, Col | ||
3 4 5 6 | ||
Row 2, Col 1 Row 2, Col 2 Row 2, Col Row 2, Col Row 2, Col Row 2, Col | ||
3 4 5 6 | ||
Row 3, Col 1 Row 3, Col 2 Row 3, Col Row 3, Col Row 3, Col Row 3, Col | ||
3 4 5 6 | ||
Row 4, Col 1 Row 4, Col 2 Row 4, Col Row 4, Col Row 4, Col Row 4, Col | ||
3 4 5 6 |
8 changes: 8 additions & 0 deletions
8
PwshSpectreConsole.Tests/@snapshots/Format-SpectrePadded.snapshot.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[38;5;12m╭────────────────────────╮[0m | ||
[38;5;12m│[0m [38;5;12m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m | ||
[38;5;12m│[0m Item to pad [38;5;12m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m | ||
[38;5;12m╰────────────────────────╯[0m |
61 changes: 61 additions & 0 deletions
61
PwshSpectreConsole.Tests/@snapshots/Format-SpectreRows.snapshot.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
lorem | ||
ipsum | ||
dolor | ||
sit | ||
amet | ||
consectetur | ||
adipiscing | ||
elit, | ||
sed | ||
do | ||
eiusmod | ||
tempor | ||
incididunt | ||
ut | ||
labore | ||
et | ||
dolore | ||
magna | ||
aliqua. | ||
Ut | ||
enim | ||
ad | ||
minim | ||
veniam, | ||
quis | ||
nostrud | ||
exercitation | ||
ullamco | ||
laboris | ||
nisi | ||
ut | ||
aliquip | ||
ex | ||
ea | ||
commodo | ||
consequat | ||
duis | ||
aute | ||
irure | ||
dolor | ||
in | ||
reprehenderit | ||
in | ||
voluptate | ||
velit | ||
esse | ||
cillum | ||
dolore | ||
eu | ||
fugiat | ||
nulla | ||
pariatur | ||
excepteur | ||
sint | ||
occaecat | ||
cupidatat | ||
non | ||
proident | ||
sunt | ||
in | ||
culpa |
1 change: 1 addition & 0 deletions
1
PwshSpectreConsole.Tests/@snapshots/Format-SpectreTextPath.snapshot.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
[38;5;12mC:[0m[38;5;8m/[0m[38;5;214mWindows[0m[38;5;8m/[0m[38;5;214mSystem32[0m[38;5;8m/[0m[38;5;9mcmd.exe[0m |
24 changes: 24 additions & 0 deletions
24
PwshSpectreConsole.Tests/@snapshots/New-SpectreLayout.snapshot.txt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
[38;5;2m╭─panel 1 (align bottom right)─────────────────────────────────────────────────╮[0m | ||
[38;5;2m│[0m what [38;5;2m│[0m | ||
[38;5;2m│[0m [38;5;2m│[0m | ||
[38;5;2m│[0m [38;5;2m│[0m | ||
[38;5;2m│[0m [38;5;2m│[0m | ||
[38;5;2m│[0m [38;5;2m│[0m | ||
[38;5;2m│[0m [38;5;2m│[0m | ||
[38;5;2m╰──────────────────────────────────────────────────────────────────────────────╯[0m | ||
[38;5;12m╭─panel 2──────────────────────────────╮[0m[38;5;11m╭─panel 3 (align middle center)────────╮[0m | ||
[38;5;12m│[0m hello row 2 [38;5;12m│[0m[38;5;11m│[0m [38;5;11m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m[38;5;11m│[0m [38;5;11m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m[38;5;11m│[0m [38;5;11m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m[38;5;11m│[0m [38;5;11m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m[38;5;11m│[0m [38;5;11m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m[38;5;11m│[0m [38;5;11m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m[38;5;11m│[0m test [38;5;11m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m[38;5;11m│[0m [38;5;11m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m[38;5;11m│[0m [38;5;11m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m[38;5;11m│[0m [38;5;11m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m[38;5;11m│[0m [38;5;11m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m[38;5;11m│[0m [38;5;11m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m[38;5;11m│[0m [38;5;11m│[0m | ||
[38;5;12m│[0m [38;5;12m│[0m[38;5;11m│[0m [38;5;11m│[0m | ||
[38;5;12m╰──────────────────────────────────────╯[0m[38;5;11m╰──────────────────────────────────────╯[0m |
33 changes: 33 additions & 0 deletions
33
PwshSpectreConsole.Tests/formatting/Format-SpectreAligned.tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue | ||
Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force | ||
Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force | ||
|
||
Describe "Format-SpectreAligned" { | ||
InModuleScope "PwshSpectreConsole" { | ||
|
||
BeforeEach { | ||
$testConsole = [Spectre.Console.Testing.TestConsole]::new() | ||
$testConsole.EmitAnsiSequences = $true | ||
|
||
Mock Write-AnsiConsole { | ||
$RenderableObject | Should -BeOfType [Spectre.Console.Rendering.Renderable] | ||
$testConsole.Write($RenderableObject) | ||
} | ||
} | ||
|
||
It "Should align an item" { | ||
$renderable = "testing" | Format-SpectreAligned -HorizontalAlignment Right | ||
$renderable | Should -BeOfType [Spectre.Console.Align] | ||
$renderable | Out-SpectreHost | ||
Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly | ||
} | ||
|
||
It "Should align an item in a panel horizontally and vertically" { | ||
$renderable = "testing panel" | Format-SpectreAligned -HorizontalAlignment Center -VerticalAlignment Middle | Format-SpectrePanel -Height 7 -Expand | ||
$renderable | Should -BeOfType [Spectre.Console.Panel] | ||
$renderable | Out-SpectreHost | ||
Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly | ||
{ Assert-OutputMatchesSnapshot -SnapshotName "Format-SpectreAligned" -Output $testConsole.Output } | Should -Not -Throw | ||
} | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
PwshSpectreConsole.Tests/formatting/Format-SpectreColumns.tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue | ||
Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force | ||
Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force | ||
|
||
Describe "Format-SpectreColumns" { | ||
InModuleScope "PwshSpectreConsole" { | ||
|
||
BeforeEach { | ||
$testConsole = [Spectre.Console.Testing.TestConsole]::new() | ||
$testConsole.EmitAnsiSequences = $true | ||
Mock Write-AnsiConsole { | ||
$RenderableObject | Should -BeOfType [Spectre.Console.Rendering.Renderable] | ||
$testConsole.Write($RenderableObject) | ||
} | ||
} | ||
|
||
It "Should format an array of strings into columns" { | ||
$renderable = Format-SpectreColumns -Data @("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit,", "sed", "do", "eiusmod", | ||
"tempor", "incididunt", "ut", "labore", "et", "dolore", "magna", "aliqua.", "Ut", "enim", "ad", "minim", | ||
"veniam,", "quis", "nostrud", "exercitation", "ullamco", "laboris", "nisi", "ut", "aliquip", "ex", "ea", | ||
"commodo", "consequat", "duis", "aute", "irure", "dolor", "in", "reprehenderit", "in", "voluptate", "velit", | ||
"esse", "cillum", "dolore", "eu", "fugiat", "nulla", "pariatur", "excepteur", "sint", "occaecat", | ||
"cupidatat", "non", "proident", "sunt", "in", "culpa") | ||
$renderable | Should -BeOfType [Spectre.Console.Columns] | ||
$renderable | Out-SpectreHost | ||
Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly | ||
} | ||
|
||
It "Should expand items to fill the available space" { | ||
$renderable = @("left", "middle", "right") | Foreach-Object { $_ | Format-SpectrePanel } | Format-SpectreColumns -Expand | ||
$renderable | Should -BeOfType [Spectre.Console.Columns] | ||
$renderable | Out-SpectreHost | ||
Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly | ||
{ Assert-OutputMatchesSnapshot -SnapshotName "Format-SpectreColumns.Expanded" -Output $testConsole.Output } | Should -Not -Throw | ||
} | ||
|
||
It "Should allow padding to be set" { | ||
$renderable = @("left", "middle", "right") | Foreach-Object { $_ | Format-SpectrePanel } | Format-SpectreColumns -Padding 4 | ||
$renderable | Should -BeOfType [Spectre.Console.Columns] | ||
$renderable | Out-SpectreHost | ||
$renderable.Padding.Top | Should -Be 4 | ||
$renderable.Padding.Right | Should -Be 4 | ||
$renderable.Padding.Bottom | Should -Be 4 | ||
$renderable.Padding.Left | Should -Be 4 | ||
Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly | ||
} | ||
} | ||
} |
63 changes: 63 additions & 0 deletions
63
PwshSpectreConsole.Tests/formatting/Format-SpectreException.tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue | ||
Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force | ||
Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force | ||
|
||
Describe "Format-SpectreException" { | ||
InModuleScope "PwshSpectreConsole" { | ||
|
||
BeforeEach { | ||
$testConsole = [Spectre.Console.Testing.TestConsole]::new() | ||
$testConsole.EmitAnsiSequences = $true | ||
Mock Write-AnsiConsole { | ||
$RenderableObject | Should -BeOfType [Spectre.Console.Rendering.Renderable] | ||
$testConsole.Write($RenderableObject) | ||
} | ||
} | ||
|
||
It "Should format an error record" { | ||
try { | ||
Get-ChildItem -BadParam -ErrorAction Stop | ||
} catch { | ||
$_ | Should -BeOfType [System.Management.Automation.ErrorRecord] | ||
$renderable = $_ | Format-SpectreException -ExceptionFormat ShortenEverything | ||
} | ||
$renderable | Should -BeOfType [Spectre.Console.Rows] | ||
$renderable | Out-SpectreHost | ||
Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly | ||
{ Assert-OutputMatchesSnapshot -SnapshotName "Format-SpectreException" -Output $testConsole.Output } | Should -Not -Throw | ||
} | ||
|
||
It "Should format an exception" { | ||
$testException = [System.Exception]::new("Test exception") | ||
$renderable = Format-SpectreException -Exception $testException -ExceptionFormat ShortenEverything | ||
$renderable | Should -BeOfType [Spectre.Console.Rows] | ||
$renderable | Out-SpectreHost | ||
Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly | ||
} | ||
|
||
It "Should format an exception with custom styles" { | ||
try { | ||
Get-ChildItem -BadParam -ErrorAction Stop | ||
} catch { | ||
$_ | Should -BeOfType [System.Management.Automation.ErrorRecord] | ||
$renderable = Format-SpectreException -Exception $_ -ExceptionFormat ShortenEverything -ExceptionStyle @{ | ||
Message = "Red" | ||
Exception = "White" | ||
Method = [Spectre.Console.Color]::Pink3 | ||
ParameterType = "Grey69" | ||
ParameterName = "Silver" | ||
Parenthesis = "#ff0000" | ||
Path = [Spectre.Console.Color]::Pink3 | ||
LineNumber = "Blue" | ||
Dimmed = "Grey" | ||
NonEmphasized = "Red" | ||
} | ||
} | ||
|
||
$renderable | Should -BeOfType [Spectre.Console.Rows] | ||
$renderable | Out-SpectreHost | ||
Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly | ||
{ Assert-OutputMatchesSnapshot -SnapshotName "Format-SpectreException.CustomStyles" -Output $testConsole.Output } | Should -Not -Throw | ||
} | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
PwshSpectreConsole.Tests/formatting/Format-SpectreGrid.tests.ps1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue | ||
Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force | ||
Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force | ||
|
||
Describe "Format-SpectreGrid" { | ||
InModuleScope "PwshSpectreConsole" { | ||
|
||
BeforeEach { | ||
$testConsole = [Spectre.Console.Testing.TestConsole]::new() | ||
$testConsole.EmitAnsiSequences = $true | ||
Mock Write-AnsiConsole { | ||
$RenderableObject | Should -BeOfType [Spectre.Console.Rendering.Renderable] | ||
$testConsole.Write($RenderableObject) | ||
} | ||
} | ||
|
||
It "Should format data in a grid" { | ||
$rows = 4 | ||
$cols = 6 | ||
|
||
$gridRows = @() | ||
for ($row = 1; $row -le $rows; $row++) { | ||
$columns = @() | ||
for ($col = 1; $col -le $cols; $col++) { | ||
$columns += "Row $row, Col $col" | ||
} | ||
$gridRows += New-SpectreGridRow $columns | ||
} | ||
|
||
$renderable = $gridRows | Format-SpectreGrid | ||
$renderable | Should -BeOfType [Spectre.Console.Grid] | ||
$renderable | Out-SpectreHost | ||
Assert-MockCalled -CommandName "Write-AnsiConsole" -Times 1 -Exactly | ||
{ Assert-OutputMatchesSnapshot -SnapshotName "Format-SpectreGrid" -Output $testConsole.Output } | Should -Not -Throw | ||
} | ||
} | ||
} |
Oops, something went wrong.