From 1fb66d6b73ae46bbccbadb25fb3d42b696fb6ed2 Mon Sep 17 00:00:00 2001 From: Roman Khimov Date: Mon, 12 Aug 2019 17:12:05 +0300 Subject: [PATCH] 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. --- pkg/vm/stack/array.go | 4 ++-- pkg/vm/stack/array_test.go | 16 ++++++++++++++++ pkg/vm/stack/map_test.go | 6 +++--- pkg/vm/stack/test_helper.go | 4 ++-- 4 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 pkg/vm/stack/array_test.go diff --git a/pkg/vm/stack/array.go b/pkg/vm/stack/array.go index c11730b1d..badb03cb0 100644 --- a/pkg/vm/stack/array.go +++ b/pkg/vm/stack/array.go @@ -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. diff --git a/pkg/vm/stack/array_test.go b/pkg/vm/stack/array_test.go new file mode 100644 index 000000000..92b5b3bd0 --- /dev/null +++ b/pkg/vm/stack/array_test.go @@ -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 +} diff --git a/pkg/vm/stack/map_test.go b/pkg/vm/stack/map_test.go index 2c2091dc4..071e7fcc7 100644 --- a/pkg/vm/stack/map_test.go +++ b/pkg/vm/stack/map_test.go @@ -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()) } diff --git a/pkg/vm/stack/test_helper.go b/pkg/vm/stack/test_helper.go index b2615141e..29be378dd 100644 --- a/pkg/vm/stack/test_helper.go +++ b/pkg/vm/stack/test_helper.go @@ -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 }