github.com/FenixAra/go@v0.0.0-20170127160404-96ea0918e670/src/cmd/internal/obj/line_test.go (about)

     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  	"fmt"
     9  	"testing"
    10  )
    11  
    12  func TestLineHist(t *testing.T) {
    13  	ctxt := new(Link)
    14  	ctxt.Hash = make(map[SymVer]*LSym)
    15  
    16  	ctxt.LineHist.Push(1, "a.c")
    17  	ctxt.LineHist.Push(3, "a.h")
    18  	ctxt.LineHist.Pop(5)
    19  	ctxt.LineHist.Update(7, "linedir", 2)
    20  	ctxt.LineHist.Pop(9)
    21  	ctxt.LineHist.Push(11, "b.c")
    22  	ctxt.LineHist.Pop(13)
    23  
    24  	var expect = []string{
    25  		0:  "??:0",
    26  		1:  "a.c:1",
    27  		2:  "a.c:2",
    28  		3:  "a.h:1",
    29  		4:  "a.h:2",
    30  		5:  "a.c:3",
    31  		6:  "a.c:4",
    32  		7:  "linedir:2",
    33  		8:  "linedir:3",
    34  		9:  "??:0",
    35  		10: "??:0",
    36  		11: "b.c:1",
    37  		12: "b.c:2",
    38  		13: "??:0",
    39  		14: "??:0",
    40  	}
    41  
    42  	for i, want := range expect {
    43  		f, l := linkgetline(ctxt, int32(i))
    44  		have := fmt.Sprintf("%s:%d", f.Name, l)
    45  		if have != want {
    46  			t.Errorf("linkgetline(%d) = %q, want %q", i, have, want)
    47  		}
    48  	}
    49  }