mirror of
https://github.com/zellyn/go6502.git
synced 2024-11-19 03:04:46 +00:00
51 lines
727 B
Go
51 lines
727 B
Go
package expr
|
|
|
|
import (
|
|
"testing"
|
|
)
|
|
|
|
func TestExpressionString(t *testing.T) {
|
|
tests := []struct {
|
|
expr E
|
|
want string
|
|
}{
|
|
{
|
|
E{},
|
|
"?",
|
|
},
|
|
{
|
|
E{Op: OpLeaf, Text: "*"},
|
|
"*",
|
|
},
|
|
{
|
|
E{
|
|
Op: OpPlus,
|
|
Left: &E{Op: OpLeaf, Text: "Label"},
|
|
Right: &E{Op: OpLeaf, Val: 42},
|
|
},
|
|
"(+ Label $002a)",
|
|
},
|
|
{
|
|
E{
|
|
Op: OpMinus,
|
|
Left: &E{Op: OpLeaf, Text: "Label"},
|
|
Right: &E{Op: OpLeaf, Val: 42},
|
|
},
|
|
"(- Label $002a)",
|
|
},
|
|
{
|
|
E{
|
|
Op: OpMinus,
|
|
Left: &E{Op: OpLeaf, Val: 42},
|
|
},
|
|
"(- $002a)",
|
|
},
|
|
}
|
|
for i, tt := range tests {
|
|
got := tt.expr.String()
|
|
if got != tt.want {
|
|
t.Errorf(`%d: want String(expr)="%s"; got "%s"`, i, tt.want, got)
|
|
}
|
|
}
|
|
}
|