aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/internal/obj/line_test.go
blob: 56bf5844fd32a44c3757850c393cefe3852b45e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2015 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

package obj

import (
	"fmt"
	"testing"
)

func TestLineHist(t *testing.T) {
	ctxt := new(Link)
	ctxt.Hash = make(map[SymVer]*LSym)

	ctxt.LineHist.Push(1, "a.c")
	ctxt.LineHist.Push(3, "a.h")
	ctxt.LineHist.Pop(5)
	ctxt.LineHist.Update(7, "linedir", 2)
	ctxt.LineHist.Pop(9)
	ctxt.LineHist.Push(11, "b.c")
	ctxt.LineHist.Pop(13)

	var expect = []string{
		0:  "??:0",
		1:  "a.c:1",
		2:  "a.c:2",
		3:  "a.h:1",
		4:  "a.h:2",
		5:  "a.c:3",
		6:  "a.c:4",
		7:  "linedir:2",
		8:  "linedir:3",
		9:  "??:0",
		10: "??:0",
		11: "b.c:1",
		12: "b.c:2",
		13: "??:0",
		14: "??:0",
	}

	for i, want := range expect {
		var f *LSym
		var l int32
		linkgetline(ctxt, int32(i), &f, &l)
		have := fmt.Sprintf("%s:%d", f.Name, l)
		if have != want {
			t.Errorf("linkgetline(%d) = %q, want %q", i, have, want)
		}
	}
}