暂无描述

ast_test.go 902B

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. // Copyright 2015 The Go Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style
  3. // license that can be found in the LICENSE file.
  4. package demangle
  5. import (
  6. "fmt"
  7. "testing"
  8. )
  9. func TestASTToString(t *testing.T) {
  10. var tests = []struct {
  11. input AST
  12. want string
  13. formatted string
  14. }{
  15. {
  16. &Qualified{Scope: &Name{Name: "s"}, Name: &Name{Name: "C"}},
  17. "s::C",
  18. `Qualified:
  19. Scope: s
  20. Name: C`,
  21. },
  22. {
  23. &Typed{Name: &Name{Name: "v"}, Type: &BuiltinType{"int"}},
  24. "int v",
  25. `Typed:
  26. Name: v
  27. Type: BuiltinType: int`,
  28. },
  29. }
  30. for i, test := range tests {
  31. if got := ASTToString(test.input); got != test.want {
  32. t.Errorf("ASTToString of test %d == %s, want %s", i, test.input, test.want)
  33. }
  34. if got := fmt.Sprintf("%#v", test.input); got != test.formatted {
  35. t.Errorf("Formatted test %d == %s, want %s", i, got, test.formatted)
  36. }
  37. }
  38. }