Merge pull request #2699 from nspcc-dev/add-atoi-tests

native: add some tests for stdlib's atoi
This commit is contained in:
Roman Khimov 2022-09-19 21:39:38 +07:00 committed by GitHub
commit 113c0ce781
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -62,6 +62,12 @@ func TestStdLibItoaAtoi(t *testing.T) {
actual = s.atoi10(ic, []stackitem.Item{stackitem.Make(tc.result)}) actual = s.atoi10(ic, []stackitem.Item{stackitem.Make(tc.result)})
}) })
require.Equal(t, stackitem.Make(tc.num), actual) require.Equal(t, stackitem.Make(tc.num), actual)
if tc.result[0] != '-' {
require.NotPanics(t, func() {
actual = s.atoi10(ic, []stackitem.Item{stackitem.Make("+" + tc.result)})
})
require.Equal(t, stackitem.Make(tc.num), actual)
}
} }
} }
@ -102,6 +108,8 @@ func TestStdLibItoaAtoi(t *testing.T) {
{"1", big.NewInt(13), ErrInvalidBase}, {"1", big.NewInt(13), ErrInvalidBase},
{"1", new(big.Int).Add(big.NewInt(math.MaxInt64), big.NewInt(16)), ErrInvalidBase}, {"1", new(big.Int).Add(big.NewInt(math.MaxInt64), big.NewInt(16)), ErrInvalidBase},
{"1_000", big.NewInt(10), ErrInvalidFormat}, {"1_000", big.NewInt(10), ErrInvalidFormat},
{" 1", big.NewInt(10), ErrInvalidFormat},
{"1 ", big.NewInt(10), ErrInvalidFormat},
{"FE", big.NewInt(10), ErrInvalidFormat}, {"FE", big.NewInt(10), ErrInvalidFormat},
{"XD", big.NewInt(16), ErrInvalidFormat}, {"XD", big.NewInt(16), ErrInvalidFormat},
{strings.Repeat("0", stdMaxInputLength+1), big.NewInt(10), ErrTooBigInput}, {strings.Repeat("0", stdMaxInputLength+1), big.NewInt(10), ErrTooBigInput},