mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2024-11-23 03:38:35 +00:00
Merge pull request #2314 from nspcc-dev/vm-pretty-print
vm: cut trailing spaces in `PrintOps`
This commit is contained in:
commit
f26de523fd
2 changed files with 24 additions and 4 deletions
|
@ -145,7 +145,7 @@ func (v *VM) PrintOps(out io.Writer) {
|
|||
out = os.Stdout
|
||||
}
|
||||
w := tabwriter.NewWriter(out, 0, 0, 4, ' ', 0)
|
||||
fmt.Fprintln(w, "INDEX\tOPCODE\tPARAMETER\t")
|
||||
fmt.Fprintln(w, "INDEX\tOPCODE\tPARAMETER")
|
||||
realctx := v.Context()
|
||||
ctx := realctx.Copy()
|
||||
ctx.ip = 0
|
||||
|
@ -154,10 +154,10 @@ func (v *VM) PrintOps(out io.Writer) {
|
|||
cursor := ""
|
||||
instr, parameter, err := ctx.Next()
|
||||
if ctx.ip == realctx.ip {
|
||||
cursor = "<<"
|
||||
cursor = "\t<<"
|
||||
}
|
||||
if err != nil {
|
||||
fmt.Fprintf(w, "%d\t%s\tERROR: %s\t%s\n", ctx.ip, instr, err, cursor)
|
||||
fmt.Fprintf(w, "%d\t%s\tERROR: %s%s\n", ctx.ip, instr, err, cursor)
|
||||
break
|
||||
}
|
||||
var desc = ""
|
||||
|
@ -203,7 +203,7 @@ func (v *VM) PrintOps(out io.Writer) {
|
|||
}
|
||||
}
|
||||
|
||||
fmt.Fprintf(w, "%d\t%s\t%s\t%s\n", ctx.ip, instr, desc, cursor)
|
||||
fmt.Fprintf(w, "%d\t%s\t%s%s\n", ctx.ip, instr, desc, cursor)
|
||||
if ctx.nextip >= len(ctx.prog) {
|
||||
break
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import (
|
|||
"math"
|
||||
"math/big"
|
||||
"math/rand"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/nspcc-dev/neo-go/internal/random"
|
||||
|
@ -1181,6 +1182,25 @@ func TestPICKITEM(t *testing.T) {
|
|||
})
|
||||
}
|
||||
|
||||
func TestVMPrintOps(t *testing.T) {
|
||||
w := io.NewBufBinWriter()
|
||||
emit.Bytes(w.BinWriter, make([]byte, 1000))
|
||||
emit.Opcodes(w.BinWriter, opcode.PUSH0)
|
||||
emit.Bytes(w.BinWriter, make([]byte, 8))
|
||||
|
||||
buf := bytes.NewBuffer(nil)
|
||||
v := New()
|
||||
v.Load(w.Bytes())
|
||||
v.PrintOps(buf)
|
||||
|
||||
ss := strings.Split(buf.String(), "\n")
|
||||
require.Equal(t, 5, len(ss)) // header + 3 opcodes + trailing newline
|
||||
require.True(t, len(ss[0]) < 1000)
|
||||
require.True(t, len(ss[1]) > 1000)
|
||||
require.True(t, len(ss[2]) < 1000)
|
||||
require.True(t, len(ss[3]) < 1000)
|
||||
}
|
||||
|
||||
func TestPICKITEMDupArray(t *testing.T) {
|
||||
prog := makeProgram(opcode.DUP, opcode.PUSH0, opcode.PICKITEM, opcode.ABS)
|
||||
vm := load(prog)
|
||||
|
|
Loading…
Reference in a new issue