github.com/aloncn/graphics-go@v0.0.1/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  		var f *LSym
    44  		var l int32
    45  		linkgetline(ctxt, int32(i), &f, &l)
    46  		have := fmt.Sprintf("%s:%d", f.Name, l)
    47  		if have != want {
    48  			t.Errorf("linkgetline(%d) = %q, want %q", i, have, want)
    49  		}
    50  	}
    51  }