...
Run Format

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  

View as plain text