Debian Codegraph @

ast_test.go

raw
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
5 package demangle
6
7 import (
8 "fmt"
9 "testing"
10 )
11
12 func TestASTToString(t *testing.T) {
13 var tests = []struct {
14 input AST
15 want string
16 formatted string
17 }{
18 {
19 &Qualified{Scope: &Name{Name: "s"}, Name: &Name{Name: "C"}},
20 "s::C",
21 `Qualified:
22 Scope: s
23 Name: C`,
24 },
25 {
26 &Typed{Name: &Name{Name: "v"}, Type: &BuiltinType{"int"}},
27 "int v",
28 `Typed:
29 Name: v
30 Type: BuiltinType: int`,
31 },
32 }
33
34 for i, test := range tests {
35 if got := ASTToString(test.input); got != test.want {
36 t.Errorf("ASTToString of test %d == %s, want %s", i, test.input, test.want)
37 }
38 if got := fmt.Sprintf("%#v", test.input); got != test.formatted {
39 t.Errorf("Formatted test %d == %s, want %s", i, got, test.formatted)
40 }
41 }
42 }