Skip to content

Commit d6b32b2

Browse files
committed
Format single item arrays as an array
1 parent d81fdbc commit d6b32b2

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/Format.ps1

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,11 @@ function Format-Nicely ($Value, [switch]$Pretty) {
121121
return Format-ScriptBlock -Value $Value
122122
}
123123

124+
# Check collection before Is-Value to format single item arrays
125+
if (Is-Collection -Value $Value) {
126+
return Format-Collection -Value $Value -Pretty:$Pretty
127+
}
128+
124129
if (Is-Value -Value $Value) {
125130
return $Value
126131
}
@@ -137,10 +142,6 @@ function Format-Nicely ($Value, [switch]$Pretty) {
137142
#return Format-Dictionary -Value $Value
138143
}
139144

140-
if (Is-Collection -Value $Value) {
141-
return Format-Collection -Value $Value -Pretty:$Pretty
142-
}
143-
144145
# no advanced formatting of objects in the first version, till I balance it
145146
return [string]$Value
146147
# Format-Object -Value $Value -Property (Get-DisplayProperty $Value) -Pretty:$Pretty

tst/Format.Tests.ps1

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,8 @@ Describe "Format-Nicely" {
148148
@{ Value = 1; Expected = '1' },
149149
@{ Value = (1, 2, 3); Expected = '@(1, 2, 3)' },
150150
@{ Value = 1.1; Expected = '1.1' },
151-
@{ Value = [int]; Expected = '[int]' }
151+
@{ Value = [int]; Expected = '[int]' },
152+
@{ Value = @('a'); Expected = "@('a')" }
152153
# @{ Value = [PSCustomObject] @{ Name = "Jakub" }; Expected = 'PSObject{Name=Jakub}' },
153154
#@{ Value = (Get-Process Idle); Expected = 'Diagnostics.Process{Id=0; Name=Idle}'},
154155
#@{ Value = (New-Object -Type Assertions.TestType.Person -Property @{Name = 'Jakub'; Age = 28}); Expected = "Assertions.TestType.Person{Age=28; Name=Jakub}"}

tst/functions/assertions/HaveCount.Tests.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ InPesterModuleScope {
3535

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

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

0 commit comments

Comments
 (0)