mirror of
https://github.com/apple/pkl.git
synced 2026-05-28 01:29:15 +02:00
Support _ in String[toInt|toIntOrNull|toFloat|toFloatOrNull] (#580)
The logic is the same as the Pkl parser
This commit is contained in:
@@ -233,19 +233,21 @@ examples {
|
||||
module.catch(() -> "9223372036854775808".toInt())
|
||||
module.catch(() -> "-9223372036854775809".toInt())
|
||||
module.catch(() -> "abc".toInt())
|
||||
module.catch(() -> "_1_000".toInt())
|
||||
}
|
||||
|
||||
["toIntOrNull()"] {
|
||||
"123".toIntOrNull()
|
||||
"-123".toIntOrNull()
|
||||
"1_2__3___".toInt()
|
||||
"-1_2__3___".toInt()
|
||||
"1_2__3___".toIntOrNull()
|
||||
"-1_2__3___".toIntOrNull()
|
||||
"0".toIntOrNull()
|
||||
"-0".toIntOrNull()
|
||||
"1.2".toIntOrNull()
|
||||
"9223372036854775808".toIntOrNull()
|
||||
"-9223372036854775809".toIntOrNull()
|
||||
"abc".toIntOrNull()
|
||||
"_1_2__3___".toIntOrNull()
|
||||
}
|
||||
|
||||
["toFloat()"] {
|
||||
@@ -282,13 +284,17 @@ examples {
|
||||
"-.45e-9".toFloat()
|
||||
"9e1024".toFloat()
|
||||
"-9e1024".toFloat()
|
||||
"-1_2__3___.2_e+1_".toFloat()
|
||||
module.catch(() -> "abc".toFloat())
|
||||
module.catch(() -> "123._34".toFloat())
|
||||
module.catch(() -> "123e_34".toFloat())
|
||||
}
|
||||
|
||||
["toFloatOrNull()"] {
|
||||
"0".toFloatOrNull()
|
||||
"-0".toFloatOrNull()
|
||||
"abc".toFloatOrNull()
|
||||
"_123_.1_".toFloatOrNull()
|
||||
}
|
||||
|
||||
["take()"] {
|
||||
|
||||
@@ -191,6 +191,7 @@ examples {
|
||||
"Cannot parse string as `Int`. String: \"9223372036854775808\""
|
||||
"Cannot parse string as `Int`. String: \"-9223372036854775809\""
|
||||
"Cannot parse string as `Int`. String: \"abc\""
|
||||
"Cannot parse string as `Int`. String: \"_1_000\""
|
||||
}
|
||||
["toIntOrNull()"] {
|
||||
123
|
||||
@@ -203,6 +204,7 @@ examples {
|
||||
null
|
||||
null
|
||||
null
|
||||
null
|
||||
}
|
||||
["toFloat()"] {
|
||||
0.0
|
||||
@@ -238,12 +240,16 @@ examples {
|
||||
-4.5E-10
|
||||
Infinity
|
||||
-Infinity
|
||||
-1232.0
|
||||
"Cannot parse string as `Float`. String: \"abc\""
|
||||
"Cannot parse string as `Float`. String: \"123._34\""
|
||||
"Cannot parse string as `Float`. String: \"123e_34\""
|
||||
}
|
||||
["toFloatOrNull()"] {
|
||||
0.0
|
||||
-0.0
|
||||
null
|
||||
null
|
||||
}
|
||||
["take()"] {
|
||||
""
|
||||
|
||||
Reference in New Issue
Block a user