go-pattern-examples/behavior/08_interpreter/interpreter_test.go

35 lines
494 B
Go
Raw Permalink Normal View History

2020-04-21 17:50:21 +03:00
package interpreter
import "testing"
2020-05-05 09:44:57 +03:00
func TestMeetingActionSignInterpreter(t *testing.T) {
p := &SignParser{}
p.Parse("rose -> tom")
p.Result()
p.Parse("rose <-> tom")
p.Result()
p.Parse("rose <- tom")
p.Result()
//should error
p.Parse("rose + tom")
p.Result()
}
func TestCalculatorInterpreter(t *testing.T) {
2020-04-21 17:50:21 +03:00
p := &Parser{}
p.Parse("1 + 2 + 3 - 4 + 5 - 6")
res := p.Result().Interpret()
expect := 1
if res != expect {
t.Fatalf("expect %d got %d", expect, res)
}
}