mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-26 19:42:23 +00:00
af2abedd86
It is convenient to have all reference-counting logic in a separate struct.
32 lines
594 B
Go
32 lines
594 B
Go
package vm
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestRefCounter_Add(t *testing.T) {
|
|
r := newRefCounter()
|
|
|
|
require.Equal(t, 0, r.size)
|
|
|
|
r.Add(NullItem{})
|
|
require.Equal(t, 1, r.size)
|
|
|
|
r.Add(NullItem{})
|
|
require.Equal(t, 2, r.size) // count scalar items twice
|
|
|
|
arr := NewArrayItem([]StackItem{NewByteArrayItem([]byte{1}), NewBoolItem(false)})
|
|
r.Add(arr)
|
|
require.Equal(t, 5, r.size) // array + 2 elements
|
|
|
|
r.Add(arr)
|
|
require.Equal(t, 6, r.size) // count only array
|
|
|
|
r.Remove(arr)
|
|
require.Equal(t, 5, r.size)
|
|
|
|
r.Remove(arr)
|
|
require.Equal(t, 2, r.size)
|
|
}
|