Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser/opcode: fix format function for mod opcode (#7455) #8431

Merged
merged 2 commits into from
Nov 26, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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