ast_test.go 728 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. package parser_test
  2. import (
  3. "testing"
  4. "github.com/d5/tengo/v2/parser"
  5. )
  6. func TestIdentListString(t *testing.T) {
  7. identListVar := &parser.IdentList{
  8. List: []*parser.Ident{
  9. {Name: "a"},
  10. {Name: "b"},
  11. {Name: "c"},
  12. },
  13. VarArgs: true,
  14. }
  15. expectedVar := "(a, b, ...c)"
  16. if str := identListVar.String(); str != expectedVar {
  17. t.Fatalf("expected string of %#v to be %s, got %s",
  18. identListVar, expectedVar, str)
  19. }
  20. identList := &parser.IdentList{
  21. List: []*parser.Ident{
  22. {Name: "a"},
  23. {Name: "b"},
  24. {Name: "c"},
  25. },
  26. VarArgs: false,
  27. }
  28. expected := "(a, b, c)"
  29. if str := identList.String(); str != expected {
  30. t.Fatalf("expected string of %#v to be %s, got %s",
  31. identList, expected, str)
  32. }
  33. }