ast_test.go 638 B

123456789101112131415161718192021222324252627
  1. package ast
  2. import (
  3. "github/runnignwater/monkey/token"
  4. "testing"
  5. )
  6. func TestString(t *testing.T) {
  7. program := &Program{
  8. Statements: []Statement{
  9. &LetStatement{
  10. Token: token.Token{Type: token.LET, Literal: "let"},
  11. Name: &Identifier{Token: token.Token{Type: token.IDENT, Literal: "myVar"}, Value: "myVar"},
  12. Value: &Identifier{
  13. Token: token.Token{Type: token.IDENT, Literal: "anotherVar"},
  14. Value: "anotherVar",
  15. },
  16. },
  17. },
  18. }
  19. if program.String() != "let myVar = anotherVar;" {
  20. t.Errorf("program.String() wrong. got=%q", program.String())
  21. }
  22. t.Logf("program.String, got = %q", program.String())
  23. }