Skip to content

Commit

Permalink
parser/opcode: fix format function for mod opcode (pingcap#7455)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiancaiamao committed Nov 24, 2018
1 parent 3f03b30 commit d4c968e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
2 changes: 1 addition & 1 deletion parser/opcode/opcode.go
Original file line number Diff line number Diff line change
Expand Up @@ -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])
}
17 changes: 16 additions & 1 deletion parser/opcode/opcode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,29 @@

package opcode

import "testing"
import (
"bytes"
"testing"
)

func TestT(t *testing.T) {
op := Plus
if op.String() != "plus" {
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()
Expand Down

0 comments on commit d4c968e

Please sign in to comment.