From d4c968e5bf08dc21d6264225f46d428870297efc Mon Sep 17 00:00:00 2001 From: tiancaiamao Date: Wed, 22 Aug 2018 10:42:43 +0800 Subject: [PATCH] parser/opcode: fix format function for mod opcode (#7455) --- parser/opcode/opcode.go | 2 +- parser/opcode/opcode_test.go | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/parser/opcode/opcode.go b/parser/opcode/opcode.go index 14b541cfbd5fa..f809ef45c3ce7 100644 --- a/parser/opcode/opcode.go +++ b/parser/opcode/opcode.go @@ -134,5 +134,5 @@ var opsLiteral = map[Op]string{ // Format the ExprNode into a Writer. func (o Op) Format(w io.Writer) { - fmt.Fprintf(w, opsLiteral[o]) + fmt.Fprintf(w, "%s", opsLiteral[o]) } diff --git a/parser/opcode/opcode_test.go b/parser/opcode/opcode_test.go index 98e4f9d85cf99..a4c2821b249f1 100644 --- a/parser/opcode/opcode_test.go +++ b/parser/opcode/opcode_test.go @@ -13,7 +13,10 @@ package opcode -import "testing" +import ( + "bytes" + "testing" +) func TestT(t *testing.T) { op := Plus @@ -21,6 +24,18 @@ func TestT(t *testing.T) { t.Fatalf("invalid op code") } + if len(Ops) != len(opsLiteral) { + t.Error("inconsistent count ops and opsliteral") + } + var buf bytes.Buffer + for op := range Ops { + op.Format(&buf) + if buf.String() != opsLiteral[op] { + t.Error("format op fail", op) + } + buf.Reset() + } + // Test invalid opcode defer func() { recover()