rsc.io/go@v0.0.0-20150416155037-e040fd465409/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 Linklinehist(ctxt, 1, "a.c", 0) 17 Linklinehist(ctxt, 3, "a.h", 0) 18 Linklinehist(ctxt, 5, "<pop>", 0) 19 Linklinehist(ctxt, 7, "linedir", 2) 20 Linklinehist(ctxt, 9, "<pop>", 0) 21 Linklinehist(ctxt, 11, "b.c", 0) 22 Linklinehist(ctxt, 13, "<pop>", 0) 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 }