func Test_Rot13(t *testing.T) { lexer := lex.New("rot13.b", conf, strings.NewReader(rot13Prog)) parser := parse.New("rot13.b", conf, lexer) prog := parser.Parse() var result string var tp *tape.Tape var in *strings.Reader var out bytes.Buffer expect := "V'z gur ongzna!" tp = tape.New() in = strings.NewReader("I'm the batman!") for _, i := range prog { i.Eval(tp, in, &out) } result = out.String() if result != expect { t.Errorf("normal program: expected %s, got %s", expect, result) } // reset tp = tape.New() in = strings.NewReader("I'm the batman!") out.Reset() prog = program.Optimize(prog) for _, i := range prog { i.Eval(tp, in, &out) } result = out.String() if result != expect { t.Errorf("optimized program: expected %s, got %s", expect, result) } }
func Test_HelloWorld(t *testing.T) { lexer := lex.New("hello_world.b", conf, strings.NewReader(helloWorldProg)) parser := parse.New("hello_world.b", conf, lexer) prog := parser.Parse() var result string var tp *tape.Tape var in *strings.Reader var out bytes.Buffer tp = tape.New() in = strings.NewReader("") expect := "Hello World!\n" for _, i := range prog { i.Eval(tp, in, &out) } result = out.String() if result != expect { t.Errorf("normal program: expected %s, got %s", expect, result) } // reset tp = tape.New() in = strings.NewReader("") out.Reset() prog = program.Optimize(prog) for _, i := range prog { i.Eval(tp, in, &out) } result = out.String() if result != expect { t.Errorf("optimized program: expected %s, got %s", expect, result) } }