mirror of
https://github.com/PowerShell/PowerShell
synced 2026-06-08 12:12:50 +00:00
Add support for thousands separators in [bigint] casting (#25396)
This commit is contained in:
@@ -185,4 +185,42 @@ Describe "Language Primitive Tests" -Tags "CI" {
|
||||
$test.TestHandlerReturnEnum() | Should -BeTrue
|
||||
$test.TestHandlerReturnObject() | Should -BeTrue
|
||||
}
|
||||
|
||||
It 'Handles large numbers with thousands separators that previously failed' {
|
||||
$formattedNumber = "9223372036854775,807"
|
||||
$convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint])
|
||||
$convertedValue | Should -Be 9223372036854775807
|
||||
}
|
||||
|
||||
It 'Handles extremely large numbers to verify precision' {
|
||||
$formattedNumber = "99999999999999999999999999999"
|
||||
$convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint])
|
||||
$convertedValue | Should -Be 99999999999999999999999999999
|
||||
}
|
||||
|
||||
It 'Parses mixed separators correctly' {
|
||||
$formattedNumber = "1,0000,00"
|
||||
$convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint])
|
||||
$convertedValue | Should -Be 1000000
|
||||
}
|
||||
|
||||
It 'Parses a number string using the invariant culture, irrespective of the current culture' {
|
||||
$originalCulture = [cultureinfo]::CurrentCulture
|
||||
try {
|
||||
[cultureinfo]::CurrentCulture = [cultureinfo]::GetCultureInfo("de-DE")
|
||||
$formattedNumber = "1.000" # in de-DE this means 1000
|
||||
$convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint])
|
||||
# since [bigint] uses invariant culture, this will be parsed as 1
|
||||
$convertedValue | Should -Be 1
|
||||
}
|
||||
finally {
|
||||
[cultureinfo]::CurrentCulture = $originalCulture
|
||||
}
|
||||
}
|
||||
|
||||
It 'Casts from floating-point number string to BigInteger using fallback' {
|
||||
$formattedNumber = "1.2"
|
||||
$convertedValue = [System.Management.Automation.LanguagePrimitives]::ConvertTo($formattedNumber, [bigint])
|
||||
$convertedValue | Should -Be 1
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user