mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-04 09:02:28 +00:00
compiler: support removing slice elements
Go-way of removing elements from slice is via `append` builtin. There is a separate opcode for removing elements from Arrays, which is cheaper and supported in this commit.
This commit is contained in:
parent
78948ef7af
commit
bcc11cbd74
4 changed files with 36 additions and 1 deletions
|
@ -327,6 +327,30 @@ func TestSubsliceCompound(t *testing.T) {
|
|||
require.Error(t, err)
|
||||
}
|
||||
|
||||
func TestRemove(t *testing.T) {
|
||||
t.Run("Valid", func(t *testing.T) {
|
||||
src := `package foo
|
||||
import "github.com/nspcc-dev/neo-go/pkg/interop/util"
|
||||
func Main() int {
|
||||
a := []int{11, 22, 33}
|
||||
util.Remove(a, 1)
|
||||
return len(a) + a[0] + a[1]
|
||||
}`
|
||||
eval(t, src, big.NewInt(46))
|
||||
})
|
||||
t.Run("ByteSlice", func(t *testing.T) {
|
||||
src := `package foo
|
||||
import "github.com/nspcc-dev/neo-go/pkg/interop/util"
|
||||
func Main() int {
|
||||
a := []byte{11, 22, 33}
|
||||
util.Remove(a, 1)
|
||||
return len(a)
|
||||
}`
|
||||
_, err := compiler.Compile("", strings.NewReader(src))
|
||||
require.Error(t, err)
|
||||
})
|
||||
}
|
||||
|
||||
func TestJumps(t *testing.T) {
|
||||
src := `
|
||||
package foo
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue