vm: make slice opcodes emit Buffer
This commit is contained in:
parent
c3f7832f3b
commit
a3a3a77431
2 changed files with 11 additions and 11 deletions
|
@ -642,7 +642,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
|||
panic(fmt.Sprintf("too big item: %d", l))
|
||||
}
|
||||
ab := append(a, b...)
|
||||
v.estack.PushVal(ab)
|
||||
v.estack.PushVal(NewBufferItem(ab))
|
||||
|
||||
case opcode.SUBSTR:
|
||||
l := int(v.estack.Pop().BigInt().Int64())
|
||||
|
@ -658,7 +658,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
|||
if last > len(s) {
|
||||
panic("invalid offset")
|
||||
}
|
||||
v.estack.PushVal(s[o:last])
|
||||
v.estack.PushVal(NewBufferItem(s[o:last]))
|
||||
|
||||
case opcode.LEFT:
|
||||
l := int(v.estack.Pop().BigInt().Int64())
|
||||
|
@ -669,7 +669,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
|||
if t := len(s); l > t {
|
||||
l = t
|
||||
}
|
||||
v.estack.PushVal(s[:l])
|
||||
v.estack.PushVal(NewBufferItem(s[:l]))
|
||||
|
||||
case opcode.RIGHT:
|
||||
l := int(v.estack.Pop().BigInt().Int64())
|
||||
|
@ -677,7 +677,7 @@ func (v *VM) execute(ctx *Context, op opcode.Opcode, parameter []byte) (err erro
|
|||
panic("negative length")
|
||||
}
|
||||
s := v.estack.Pop().Bytes()
|
||||
v.estack.PushVal(s[len(s)-l:])
|
||||
v.estack.PushVal(NewBufferItem(s[len(s)-l:]))
|
||||
|
||||
case opcode.DEPTH:
|
||||
v.estack.PushVal(v.estack.Len())
|
||||
|
|
|
@ -1753,9 +1753,9 @@ func TestCAT(t *testing.T) {
|
|||
arg := make([]byte, MaxItemSize/2+1)
|
||||
runWithArgs(t, prog, nil, arg, arg)
|
||||
})
|
||||
t.Run("Good", getTestFuncForVM(prog, []byte("abcdef"), []byte("abc"), []byte("def")))
|
||||
t.Run("Int0ByteArray", getTestFuncForVM(prog, []byte{}, 0, []byte{}))
|
||||
t.Run("ByteArrayInt1", getTestFuncForVM(prog, []byte{1}, []byte{}, 1))
|
||||
t.Run("Good", getTestFuncForVM(prog, NewBufferItem([]byte("abcdef")), []byte("abc"), []byte("def")))
|
||||
t.Run("Int0ByteArray", getTestFuncForVM(prog, NewBufferItem([]byte{}), 0, []byte{}))
|
||||
t.Run("ByteArrayInt1", getTestFuncForVM(prog, NewBufferItem([]byte{1}), []byte{}, 1))
|
||||
}
|
||||
|
||||
func TestSUBSTR(t *testing.T) {
|
||||
|
@ -1763,7 +1763,7 @@ func TestSUBSTR(t *testing.T) {
|
|||
t.Run("NoArgument", getTestFuncForVM(prog, nil))
|
||||
t.Run("OneArgument", getTestFuncForVM(prog, nil, 1))
|
||||
t.Run("TwoArguments", getTestFuncForVM(prog, nil, 0, 2))
|
||||
t.Run("Good", getTestFuncForVM(prog, []byte("bc"), []byte("abcdef"), 1, 2))
|
||||
t.Run("Good", getTestFuncForVM(prog, NewBufferItem([]byte("bc")), []byte("abcdef"), 1, 2))
|
||||
t.Run("BadOffset", getTestFuncForVM(prog, nil, []byte("abcdef"), 7, 1))
|
||||
t.Run("BigLen", getTestFuncForVM(prog, nil, []byte("abcdef"), 1, 6))
|
||||
t.Run("NegativeOffset", getTestFuncForVM(prog, nil, []byte("abcdef"), -1, 3))
|
||||
|
@ -1786,8 +1786,8 @@ func TestLEFT(t *testing.T) {
|
|||
t.Run("NoArgument", getTestFuncForVM(prog, nil))
|
||||
t.Run("NoString", getTestFuncForVM(prog, nil, 2))
|
||||
t.Run("NegativeLen", getTestFuncForVM(prog, nil, "abcdef", -1))
|
||||
t.Run("Good", getTestFuncForVM(prog, "ab", "abcdef", 2))
|
||||
t.Run("GoodBigLen", getTestFuncForVM(prog, "abcdef", "abcdef", 8))
|
||||
t.Run("Good", getTestFuncForVM(prog, NewBufferItem([]byte("ab")), "abcdef", 2))
|
||||
t.Run("GoodBigLen", getTestFuncForVM(prog, NewBufferItem([]byte("abcdef")), "abcdef", 8))
|
||||
}
|
||||
|
||||
func TestRIGHT(t *testing.T) {
|
||||
|
@ -1795,7 +1795,7 @@ func TestRIGHT(t *testing.T) {
|
|||
t.Run("NoArgument", getTestFuncForVM(prog, nil))
|
||||
t.Run("NoString", getTestFuncForVM(prog, nil, 2))
|
||||
t.Run("NegativeLen", getTestFuncForVM(prog, nil, "abcdef", -1))
|
||||
t.Run("Good", getTestFuncForVM(prog, "ef", "abcdef", 2))
|
||||
t.Run("Good", getTestFuncForVM(prog, NewBufferItem([]byte("ef")), "abcdef", 2))
|
||||
t.Run("BadLen", getTestFuncForVM(prog, nil, "abcdef", 8))
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue