...

Source file src/debug/gosym/symtab_test.go

Documentation: debug/gosym

		 1  // Copyright 2016 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 gosym
		 6  
		 7  import (
		 8  	"fmt"
		 9  	"testing"
		10  )
		11  
		12  func assertString(t *testing.T, dsc, out, tgt string) {
		13  	if out != tgt {
		14  		t.Fatalf("Expected: %q Actual: %q for %s", tgt, out, dsc)
		15  	}
		16  }
		17  
		18  func TestStandardLibPackage(t *testing.T) {
		19  	s1 := Sym{Name: "io.(*LimitedReader).Read"}
		20  	s2 := Sym{Name: "io.NewSectionReader"}
		21  	assertString(t, fmt.Sprintf("package of %q", s1.Name), s1.PackageName(), "io")
		22  	assertString(t, fmt.Sprintf("package of %q", s2.Name), s2.PackageName(), "io")
		23  	assertString(t, fmt.Sprintf("receiver of %q", s1.Name), s1.ReceiverName(), "(*LimitedReader)")
		24  	assertString(t, fmt.Sprintf("receiver of %q", s2.Name), s2.ReceiverName(), "")
		25  }
		26  
		27  func TestStandardLibPathPackage(t *testing.T) {
		28  	s1 := Sym{Name: "debug/gosym.(*LineTable).PCToLine"}
		29  	s2 := Sym{Name: "debug/gosym.NewTable"}
		30  	assertString(t, fmt.Sprintf("package of %q", s1.Name), s1.PackageName(), "debug/gosym")
		31  	assertString(t, fmt.Sprintf("package of %q", s2.Name), s2.PackageName(), "debug/gosym")
		32  	assertString(t, fmt.Sprintf("receiver of %q", s1.Name), s1.ReceiverName(), "(*LineTable)")
		33  	assertString(t, fmt.Sprintf("receiver of %q", s2.Name), s2.ReceiverName(), "")
		34  }
		35  
		36  func TestRemotePackage(t *testing.T) {
		37  	s1 := Sym{Name: "github.com/docker/doc.ker/pkg/mflag.(*FlagSet).PrintDefaults"}
		38  	s2 := Sym{Name: "github.com/docker/doc.ker/pkg/mflag.PrintDefaults"}
		39  	assertString(t, fmt.Sprintf("package of %q", s1.Name), s1.PackageName(), "github.com/docker/doc.ker/pkg/mflag")
		40  	assertString(t, fmt.Sprintf("package of %q", s2.Name), s2.PackageName(), "github.com/docker/doc.ker/pkg/mflag")
		41  	assertString(t, fmt.Sprintf("receiver of %q", s1.Name), s1.ReceiverName(), "(*FlagSet)")
		42  	assertString(t, fmt.Sprintf("receiver of %q", s2.Name), s2.ReceiverName(), "")
		43  }
		44  
		45  func TestIssue29551(t *testing.T) {
		46  	symNames := []string{
		47  		"type..eq.[9]debug/elf.intName",
		48  		"type..hash.debug/elf.ProgHeader",
		49  		"type..eq.runtime._panic",
		50  		"type..hash.struct { runtime.gList; runtime.n int32 }",
		51  		"go.(*struct { sync.Mutex; math/big.table [64]math/big",
		52  	}
		53  
		54  	for _, symName := range symNames {
		55  		s := Sym{Name: symName}
		56  		assertString(t, fmt.Sprintf("package of %q", s.Name), s.PackageName(), "")
		57  	}
		58  }
		59  

View as plain text