Skip to content

Commit 47c33d3

Browse files
fflatengithub-actions
authored and
github-actions
committed
Format single item arrays as an array
1 parent 7a0ea06 commit 47c33d3

File tree

3 files changed

+8
-6
lines changed

3 files changed

+8
-6
lines changed

src/Format.ps1

+5-4
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,11 @@ function Format-Nicely ($Value, [switch]$Pretty) {
125125
return Format-ScriptBlock -Value $Value
126126
}
127127

128+
# Check collection before Is-Value to format single item arrays
129+
if (Is-Collection -Value $Value) {
130+
return Format-Collection -Value $Value -Pretty:$Pretty
131+
}
132+
128133
if (Is-Value -Value $Value) {
129134
return $Value
130135
}
@@ -141,10 +146,6 @@ function Format-Nicely ($Value, [switch]$Pretty) {
141146
#return Format-Dictionary -Value $Value
142147
}
143148

144-
if (Is-Collection -Value $Value) {
145-
return Format-Collection -Value $Value -Pretty:$Pretty
146-
}
147-
148149
# no advanced formatting of objects in the first version, till I balance it
149150
return [string]$Value
150151
# Format-Object -Value $Value -Property (Get-DisplayProperty $Value) -Pretty:$Pretty

tst/Format.Tests.ps1

+2-1
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,8 @@ Describe "Format-Nicely" {
155155
@{ Value = 1; Expected = '1' },
156156
@{ Value = (1, 2, 3); Expected = '@(1, 2, 3)' },
157157
@{ Value = 1.1; Expected = '1.1' },
158-
@{ Value = [int]; Expected = '[int]' }
158+
@{ Value = [int]; Expected = '[int]' },
159+
@{ Value = @('a'); Expected = "@('a')" }
159160
# @{ Value = [PSCustomObject] @{ Name = "Jakub" }; Expected = 'PSObject{Name=Jakub}' },
160161
#@{ Value = (Get-Process Idle); Expected = 'Diagnostics.Process{Id=0; Name=Idle}'},
161162
#@{ 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

+1-1
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)