mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-01-11 01:20:37 +00:00
pkg/vm/stack: improve Array testing code slightly
GolangCI complained: testArray is unused (from deadcode) But this function was actually wrong being a copy-paste of testMakeStackMap(), it also didn't conform to testMake... naming scheme, so this fixes it. To make thing more uniform NewArray() was also changed to return error, map_test.go code adjusted to this changes and finally array_test.go was added as a stub for future Array testing.
This commit is contained in:
parent
3bc195659a
commit
1fb66d6b73
4 changed files with 23 additions and 7 deletions
|
@ -22,11 +22,11 @@ func (a *Array) Value() []Item {
|
|||
}
|
||||
|
||||
// NewArray returns a new Array.
|
||||
func NewArray(val []Item) *Array {
|
||||
func NewArray(val []Item) (*Array, error) {
|
||||
return &Array{
|
||||
&abstractItem{},
|
||||
val,
|
||||
}
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Hash overrides the default abstract hash method.
|
||||
|
|
16
pkg/vm/stack/array_test.go
Normal file
16
pkg/vm/stack/array_test.go
Normal file
|
@ -0,0 +1,16 @@
|
|||
package stack
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
// it's a stub at the moment, but will need it anyway
|
||||
// "github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestArray(t *testing.T) {
|
||||
var a Item = testMakeStackInt(t, 3)
|
||||
var b Item = testMakeStackInt(t, 6)
|
||||
var c Item = testMakeStackInt(t, 9)
|
||||
var ta = testMakeArray(t, []Item{a, b, c})
|
||||
_ = ta
|
||||
}
|
|
@ -16,7 +16,7 @@ func TestMap(t *testing.T) {
|
|||
b: a,
|
||||
})
|
||||
var e = NewContext([]byte{1, 2, 3, 4})
|
||||
var f = NewArray([]Item{a, b})
|
||||
var f = testMakeArray(t, []Item{a, b})
|
||||
|
||||
val := map[Item]Item{
|
||||
a: c,
|
||||
|
@ -47,7 +47,7 @@ func TestMap(t *testing.T) {
|
|||
valueE, _ := m.ValueOfKey(NewContext([]byte{1, 2, 3, 4}))
|
||||
assert.Equal(t, d, valueE)
|
||||
|
||||
valueF, _ := m.ValueOfKey(NewArray([]Item{a, b}))
|
||||
valueF, _ := m.ValueOfKey(testMakeArray(t, []Item{a, b}))
|
||||
assert.Equal(t, e, valueF)
|
||||
|
||||
valueX, _ := m.ValueOfKey(NewByteArray([]byte{1, 2, 35}))
|
||||
|
@ -100,7 +100,7 @@ func TestMap(t *testing.T) {
|
|||
assert.Nil(t, err)
|
||||
assert.Equal(t, true, checkContext.Value())
|
||||
|
||||
checkArray, err := CompareHash(f, NewArray([]Item{a, b}))
|
||||
checkArray, err := CompareHash(f, testMakeArray(t, []Item{a, b}))
|
||||
assert.Nil(t, err)
|
||||
assert.Equal(t, true, checkArray.Value())
|
||||
}
|
||||
|
|
|
@ -49,8 +49,8 @@ func testMakeStackMap(t *testing.T, m map[Item]Item) *Map {
|
|||
return a
|
||||
}
|
||||
|
||||
func testArray(t *testing.T, m map[Item]Item) *Map {
|
||||
a, err := NewMap(m)
|
||||
func testMakeArray(t *testing.T, v []Item) *Array {
|
||||
a, err := NewArray(v)
|
||||
assert.Nil(t, err)
|
||||
return a
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue