Skip to content

Commit

Permalink
Format single item arrays as an array
Browse files Browse the repository at this point in the history
  • Loading branch information
fflaten committed Mar 28, 2023
1 parent d81fdbc commit d6b32b2
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
9 changes: 5 additions & 4 deletions src/Format.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,11 @@ function Format-Nicely ($Value, [switch]$Pretty) {
return Format-ScriptBlock -Value $Value
}

# Check collection before Is-Value to format single item arrays
if (Is-Collection -Value $Value) {
return Format-Collection -Value $Value -Pretty:$Pretty
}

if (Is-Value -Value $Value) {
return $Value
}
Expand All @@ -137,10 +142,6 @@ function Format-Nicely ($Value, [switch]$Pretty) {
#return Format-Dictionary -Value $Value
}

if (Is-Collection -Value $Value) {
return Format-Collection -Value $Value -Pretty:$Pretty
}

# no advanced formatting of objects in the first version, till I balance it
return [string]$Value
# Format-Object -Value $Value -Property (Get-DisplayProperty $Value) -Pretty:$Pretty
Expand Down
3 changes: 2 additions & 1 deletion tst/Format.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,8 @@ Describe "Format-Nicely" {
@{ Value = 1; Expected = '1' },
@{ Value = (1, 2, 3); Expected = '@(1, 2, 3)' },
@{ Value = 1.1; Expected = '1.1' },
@{ Value = [int]; Expected = '[int]' }
@{ Value = [int]; Expected = '[int]' },
@{ Value = @('a'); Expected = "@('a')" }
# @{ Value = [PSCustomObject] @{ Name = "Jakub" }; Expected = 'PSObject{Name=Jakub}' },
#@{ Value = (Get-Process Idle); Expected = 'Diagnostics.Process{Id=0; Name=Idle}'},
#@{ Value = (New-Object -Type Assertions.TestType.Person -Property @{Name = 'Jakub'; Age = 28}); Expected = "Assertions.TestType.Person{Age=28; Name=Jakub}"}
Expand Down
2 changes: 1 addition & 1 deletion tst/functions/assertions/HaveCount.Tests.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ InPesterModuleScope {

It "returns the correct assertion message when collection is not empty" {
$err = { @(1) | Should -HaveCount 0 -Because 'reason' } | Verify-AssertionFailed
$err.Exception.Message | Verify-Equal 'Expected an empty collection, because reason, but got collection with size 1 1.'
$err.Exception.Message | Verify-Equal 'Expected an empty collection, because reason, but got collection with size 1 @(1).'
}

It "validates the expected size to be bigger than 0" {
Expand Down

0 comments on commit d6b32b2

Please sign in to comment.