Skip to content

Commit 352d6b0

Browse files
Merge pull request #165 from gabriel-samfira/fix-casting-zero-as-bigint
Fix broken if comparison
2 parents fca7cce + 47a2875 commit 352d6b0

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

Tests/powershell-yaml.Tests.ps1

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,8 @@ wishlist:
254254
scientificNotationInt: 1e+3
255255
scientificNotationBigInt: 1e+40
256256
intWithTag: !!int "42"
257+
zeroIntWithTag: !!int "0"
258+
zeroIntWithoutTag: 0
257259
scientificNotationIntWithTag: !!int "1e+3"
258260
price : 55.34
259261
total: 4443.52
@@ -302,6 +304,8 @@ bools:
302304
scientificNotationInt = [int32]1000
303305
scientificNotationBigInt = [System.Numerics.BigInteger]::Parse("10000000000000000000000000000000000000000")
304306
intWithTag = 42
307+
zeroIntWithTag = 0
308+
zeroIntWithoutTag = 0
305309
scientificNotationIntWithTag = 1000
306310
}
307311
);
@@ -351,6 +355,10 @@ bools:
351355
$product['aStringTatLooksLikeAFloat'] | Should -BeOfType ([string])
352356
$product['aStringThatLooksLikeAnInt'] | Should -Be $expectedProduct['aStringThatLooksLikeAnInt']
353357
$product['aStringThatLooksLikeAnInt'] | Should -BeOfType ([string])
358+
$product['zeroIntWithTag'] | Should -Be $expectedProduct['zeroIntWithTag']
359+
$product['zeroIntWithTag'] | Should -BeOfType ([int32])
360+
$product['zeroIntWithoutTag'] | Should -Be $expectedProduct['zeroIntWithoutTag']
361+
$product['zeroIntWithoutTag'] | Should -BeOfType ([int32])
354362
$product['scientificNotationInt'] | Should -Be $expectedProduct['scientificNotationInt']
355363
$product['scientificNotationInt'] | Should -BeOfType ([int32])
356364
$product['scientificNotationBigInt'] | Should -Be $expectedProduct['scientificNotationBigInt']

powershell-yaml.psm1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ function Convert-ValueToProperType {
161161
}
162162
foreach ($i in $intTypes) {
163163
$asIntType = $parsedValue -as $i
164-
if($asIntType) {
164+
if($null -ne $asIntType) {
165165
return $asIntType
166166
}
167167
}
@@ -212,7 +212,7 @@ function Convert-ValueToProperType {
212212
$types = @([int], [long])
213213
foreach($i in $types){
214214
$asType = $parsedValue -as $i
215-
if($asType) {
215+
if($null -ne $asType) {
216216
return $asType
217217
}
218218
}

0 commit comments

Comments
 (0)