ast_test.go 770 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. package ast
  2. import (
  3. "testing"
  4. "code.osinet.fr/fgm/waiig15/token"
  5. )
  6. func TestString(t *testing.T) {
  7. // Build a program made of a single "let myBra = anotherVar;" statement.
  8. program := &Program{
  9. Statements: []Statement{
  10. &LetStatement{
  11. Token: token.Token{
  12. Type: token.LET,
  13. Literal: "let",
  14. },
  15. Name: &Identifier{
  16. Token: token.Token{
  17. Type: token.IDENT,
  18. Literal: "myVar",
  19. },
  20. Value: "myVar",
  21. },
  22. Value: &Identifier{
  23. Token: token.Token{
  24. Type: token.IDENT,
  25. Literal: "anotherVar",
  26. },
  27. Value: "anotherVar",
  28. },
  29. },
  30. },
  31. }
  32. programString := program.String()
  33. if programString != "let myVar = anotherVar;" {
  34. t.Errorf("program.String() wrong. got=%q", programString)
  35. }
  36. }