Source file src/cmd/internal/obj/line_test.go

     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 obj
     6  
     7  import (
     8  	"cmd/internal/src"
     9  	"fmt"
    10  	"testing"
    11  )
    12  
    13  func TestLinkgetlineFromPos(t *testing.T) {
    14  	ctxt := new(Link)
    15  	ctxt.hash = make(map[string]*LSym)
    16  	ctxt.statichash = make(map[string]*LSym)
    17  
    18  	afile := src.NewFileBase("a.go", "a.go")
    19  	bfile := src.NewFileBase("b.go", "/foo/bar/b.go")
    20  	lfile := src.NewLinePragmaBase(src.MakePos(afile, 8, 1), "linedir", "linedir", 100, 1)
    21  
    22  	var tests = []struct {
    23  		pos  src.Pos
    24  		want string
    25  	}{
    26  		{src.NoPos, "??:0"},
    27  		{src.MakePos(afile, 1, 0), "a.go:1"},
    28  		{src.MakePos(afile, 2, 0), "a.go:2"},
    29  		{src.MakePos(bfile, 10, 4), "/foo/bar/b.go:10"},
    30  		{src.MakePos(lfile, 10, 0), "linedir:102"}, // 102 == 100 + (10 - (7+1))
    31  	}
    32  
    33  	for _, test := range tests {
    34  		f, l := linkgetlineFromPos(ctxt, ctxt.PosTable.XPos(test.pos))
    35  		got := fmt.Sprintf("%s:%d", f, l)
    36  		if got != src.FileSymPrefix+test.want {
    37  			t.Errorf("linkgetline(%v) = %q, want %q", test.pos, got, test.want)
    38  		}
    39  	}
    40  }
    41  

View as plain text