-
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.
Fully qualify .net classes, the using statements make them shorter bu…
…t you can't copy paste chunks for testing easily. Add format-spectrerows
- Loading branch information
1 parent
5314161
commit dca82c1
Showing
46 changed files
with
663 additions
and
603 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
90 changes: 45 additions & 45 deletions
90
PwshSpectreConsole.Tests/writing/Write-SpectreHost.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 |
---|---|---|
@@ -1,46 +1,46 @@ | ||
Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue | ||
Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force | ||
Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force | ||
|
||
Describe "Write-SpectreHost" { | ||
InModuleScope "PwshSpectreConsole" { | ||
BeforeEach { | ||
$testConsole = [Spectre.Console.Testing.TestConsole]::new() | ||
$testConsole.EmitAnsiSequences = $true | ||
$testMessage = Get-RandomString | ||
$testMessage | Out-Null | ||
Mock Write-SpectreHostInternalMarkup { | ||
$Message | Should -Be $testMessage | ||
[AnsiConsoleExtensions]::Markup($testConsole, $Message) | ||
} | ||
Mock Write-SpectreHostInternalMarkupLine { | ||
$Message | Should -Be $testMessage | ||
[AnsiConsoleExtensions]::MarkupLine($testConsole, $Message) | ||
} | ||
} | ||
|
||
It "writes a message" { | ||
Write-SpectreHost -Message $testMessage | ||
Assert-MockCalled -CommandName "Write-SpectreHostInternalMarkupLine" -Times 1 -Exactly | ||
$testConsole.Output.Split("`n").Count | Should -Be 2 | ||
} | ||
|
||
It "accepts pipeline input" { | ||
$testMessage | Write-SpectreHost | ||
Assert-MockCalled -CommandName "Write-SpectreHostInternalMarkupLine" -Times 1 -Exactly | ||
$testConsole.Output.Split("`n").Count | Should -Be 2 | ||
} | ||
|
||
It "handles nonewline" { | ||
Write-SpectreHost -Message $testMessage -NoNewline | ||
Assert-MockCalled -CommandName "Write-SpectreHostInternalMarkup" -Times 1 -Exactly | ||
$testConsole.Output.Split("`n").Count | Should -Be 1 | ||
} | ||
|
||
It "Should match the snapshot" { | ||
$testMessage = "[#00ff00]Hello[/], [DeepSkyBlue3_1]World![/] :smiling_face_with_sunglasses: Yay!" | ||
Write-SpectreHost $testMessage | ||
{ Assert-OutputMatchesSnapshot -SnapshotName "Write-SpectreHost" -Output $testConsole.Output } | Should -Not -Throw | ||
} | ||
} | ||
Remove-Module PwshSpectreConsole -Force -ErrorAction SilentlyContinue | ||
Import-Module "$PSScriptRoot\..\..\PwshSpectreConsole\PwshSpectreConsole.psd1" -Force | ||
Import-Module "$PSScriptRoot\..\TestHelpers.psm1" -Force | ||
|
||
Describe "Write-SpectreHost" { | ||
InModuleScope "PwshSpectreConsole" { | ||
BeforeEach { | ||
$testConsole = [Spectre.Console.Testing.TestConsole]::new() | ||
$testConsole.EmitAnsiSequences = $true | ||
$testMessage = Get-RandomString | ||
$testMessage | Out-Null | ||
Mock Write-SpectreHostInternalMarkup { | ||
$Message | Should -Be $testMessage | ||
[Spectre.Console.AnsiConsoleExtensions]::Markup($testConsole, $Message) | ||
} | ||
Mock Write-SpectreHostInternalMarkupLine { | ||
$Message | Should -Be $testMessage | ||
[Spectre.Console.AnsiConsoleExtensions]::MarkupLine($testConsole, $Message) | ||
} | ||
} | ||
|
||
It "writes a message" { | ||
Write-SpectreHost -Message $testMessage | ||
Assert-MockCalled -CommandName "Write-SpectreHostInternalMarkupLine" -Times 1 -Exactly | ||
$testConsole.Output.Split("`n").Count | Should -Be 2 | ||
} | ||
|
||
It "accepts pipeline input" { | ||
$testMessage | Write-SpectreHost | ||
Assert-MockCalled -CommandName "Write-SpectreHostInternalMarkupLine" -Times 1 -Exactly | ||
$testConsole.Output.Split("`n").Count | Should -Be 2 | ||
} | ||
|
||
It "handles nonewline" { | ||
Write-SpectreHost -Message $testMessage -NoNewline | ||
Assert-MockCalled -CommandName "Write-SpectreHostInternalMarkup" -Times 1 -Exactly | ||
$testConsole.Output.Split("`n").Count | Should -Be 1 | ||
} | ||
|
||
It "Should match the snapshot" { | ||
$testMessage = "[#00ff00]Hello[/], [DeepSkyBlue3_1]World![/] :smiling_face_with_sunglasses: Yay!" | ||
Write-SpectreHost $testMessage | ||
{ Assert-OutputMatchesSnapshot -SnapshotName "Write-SpectreHost" -Output $testConsole.Output } | Should -Not -Throw | ||
} | ||
} | ||
} |
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
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
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
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
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 |
---|---|---|
@@ -1,44 +1,43 @@ | ||
using namespace Spectre.Console | ||
|
||
<# | ||
.SYNOPSIS | ||
Converts a string representation of a color to a Color object. | ||
.DESCRIPTION | ||
This function takes a string representation of a color and converts it to a Color object. The input color can be in the form of a named color or a hexadecimal color code. | ||
.PARAMETER Color | ||
The color to convert. This parameter is mandatory and accepts input from the pipeline. | ||
.EXAMPLE | ||
'red' | Convert-ToSpectreColor | ||
.EXAMPLE | ||
'#FF0000' | Convert-ToSpectreColor | ||
.EXAMPLE | ||
[Color]::Salmon1 | Convert-ToSpectreColor | ||
#> | ||
function Convert-ToSpectreColor { | ||
param ( | ||
[Parameter(ValueFromPipeline, Mandatory)] | ||
[object] $Color | ||
) | ||
try { | ||
# Just return the console color object | ||
if ($Color -is [Color]) { | ||
return $Color | ||
} | ||
# Already validated in validation attribute | ||
if ($Color.StartsWith("#")) { | ||
$hexString = $Color -replace '^#', '' | ||
$hexBytes = [System.Convert]::FromHexString($hexString) | ||
return [Color]::new($hexBytes[0], $hexBytes[1], $hexBytes[2]) | ||
} | ||
|
||
# Validated in attribute as a real color already | ||
return [Color]::$Color | ||
} catch { | ||
return $script:AccentColor | ||
} | ||
} | ||
|
||
<# | ||
.SYNOPSIS | ||
Converts a string representation of a color to a Color object. | ||
.DESCRIPTION | ||
This function takes a string representation of a color and converts it to a Color object. The input color can be in the form of a named color or a hexadecimal color code. | ||
.PARAMETER Color | ||
The color to convert. This parameter is mandatory and accepts input from the pipeline. | ||
.EXAMPLE | ||
'red' | Convert-ToSpectreColor | ||
.EXAMPLE | ||
'#FF0000' | Convert-ToSpectreColor | ||
.EXAMPLE | ||
[Spectre.Console.Color]::Salmon1 | Convert-ToSpectreColor | ||
#> | ||
function Convert-ToSpectreColor { | ||
param ( | ||
[Parameter(ValueFromPipeline, Mandatory)] | ||
[object] $Color | ||
) | ||
try { | ||
# Just return the console color object | ||
if ($Color -is [Spectre.Console.Color]) { | ||
return $Color | ||
} | ||
# Already validated in validation attribute | ||
if ($Color.StartsWith("#")) { | ||
$hexString = $Color -replace '^#', '' | ||
$hexBytes = [System.Convert]::FromHexString($hexString) | ||
return [Spectre.Console.Color]::new($hexBytes[0], $hexBytes[1], $hexBytes[2]) | ||
} | ||
|
||
# Validated in attribute as a real color already | ||
return [Spectre.Console.Color]::$Color | ||
} catch { | ||
return $script:AccentColor | ||
} | ||
} |
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
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
Oops, something went wrong.