From 1b753cd4bc3f7ed37c47b9b2ba564075d2bdd491 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 19 Sep 2022 16:18:53 +0300 Subject: [PATCH] native: add some tests for stdlib's atoi See neo-project/neo#2804 and neo-project/neo#2813. We're already compatible. --- pkg/core/native/std_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/core/native/std_test.go b/pkg/core/native/std_test.go index 2ee87f31a..48b81b526 100644 --- a/pkg/core/native/std_test.go +++ b/pkg/core/native/std_test.go @@ -62,6 +62,12 @@ func TestStdLibItoaAtoi(t *testing.T) { actual = s.atoi10(ic, []stackitem.Item{stackitem.Make(tc.result)}) }) 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", new(big.Int).Add(big.NewInt(math.MaxInt64), big.NewInt(16)), ErrInvalidBase}, {"1_000", big.NewInt(10), ErrInvalidFormat}, + {" 1", big.NewInt(10), ErrInvalidFormat}, + {"1 ", big.NewInt(10), ErrInvalidFormat}, {"FE", big.NewInt(10), ErrInvalidFormat}, {"XD", big.NewInt(16), ErrInvalidFormat}, {strings.Repeat("0", stdMaxInputLength+1), big.NewInt(10), ErrTooBigInput},