diff options
author | Jo-Philipp Wich <jo@mein.io> | 2022-06-01 12:31:10 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2022-06-01 12:53:26 +0200 |
commit | 9efbe183d7805eb60652a3745ec48cd32682ef8d (patch) | |
tree | 469c4727d14938b1a28bb53b6192891682442d6b /tests | |
parent | 9b35df7b37f21043f4be0bdba011000ad4f7cf0f (diff) |
lib: refactor `uc_int()`
For string cases, turn `int()` into a thin `strtoll()` wrapper which
attempts to parse the initial portion of the string as a decimal integer
literal, optionally preceded by white space and a sign character.
Also introduce an optional `base` argument for string cases while we're
at it and adjust the existing stdlib test case accordingly.
The function now behaves mostly the same as ECMAScript `parseInt(val, 10)`
for string cases, means it will recognize `012` as `12` and not `10` and
it will accept trailing non-digit characters after the initial portition
of the input string.
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
Diffstat (limited to 'tests')
-rw-r--r-- | tests/custom/03_stdlib/08_int | 8 | ||||
-rw-r--r-- | tests/custom/04_bugs/29_empty_string_as_number | 8 |
2 files changed, 7 insertions, 9 deletions
diff --git a/tests/custom/03_stdlib/08_int b/tests/custom/03_stdlib/08_int index a6b5923..12db299 100644 --- a/tests/custom/03_stdlib/08_int +++ b/tests/custom/03_stdlib/08_int @@ -30,13 +30,13 @@ Returns `NaN` if the conversion result is out of range. 0, 123, 456, - 0, - "NaN", "NaN", - 4096, "NaN", - 127, "NaN", + 0, + 0, + 177, + 145, -96 ] -- End -- diff --git a/tests/custom/04_bugs/29_empty_string_as_number b/tests/custom/04_bugs/29_empty_string_as_number index 675f8a1..51a93b2 100644 --- a/tests/custom/04_bugs/29_empty_string_as_number +++ b/tests/custom/04_bugs/29_empty_string_as_number @@ -1,10 +1,9 @@ -When an empty string was casted to a number, e.g. explicitly through `+` -or `int()` or implicitly through numerical calculations, it was incorrectly -treated as `NaN` and not `0`. +When an empty string was explicitly casted to a number through `+` or +implicitly through numerical calculations, it was incorrectly treated +as `NaN` and not `0`. -- Testcase -- {{ +"" }} -{{ int("") }} {{ "" + 0 }} {{ "" - 0.0 }} -- End -- @@ -13,5 +12,4 @@ treated as `NaN` and not `0`. 0 0 0 -0 -- End -- |