diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-16 19:25:22 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-16 19:25:22 +0000 |
commit | f6ad4dcef54c5ce997a4bad5a6d86de229015700 (patch) | |
tree | 7cfa4e31ace5c2bd95c72b154d15af494b2bcbef /src/cmd/internal/obj/line_test.go | |
parent | Initial commit. (diff) | |
download | golang-1.22-f6ad4dcef54c5ce997a4bad5a6d86de229015700.tar.xz golang-1.22-f6ad4dcef54c5ce997a4bad5a6d86de229015700.zip |
Adding upstream version 1.22.1.upstream/1.22.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/cmd/internal/obj/line_test.go')
-rw-r--r-- | src/cmd/internal/obj/line_test.go | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/src/cmd/internal/obj/line_test.go b/src/cmd/internal/obj/line_test.go new file mode 100644 index 0000000..de7ef1a --- /dev/null +++ b/src/cmd/internal/obj/line_test.go @@ -0,0 +1,46 @@ +// 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 ( + "cmd/internal/src" + "fmt" + "testing" +) + +func TestGetFileSymbolAndLine(t *testing.T) { + ctxt := new(Link) + ctxt.hash = make(map[string]*LSym) + ctxt.statichash = make(map[string]*LSym) + + afile := src.NewFileBase("a.go", "a.go") + bfile := src.NewFileBase("b.go", "/foo/bar/b.go") + lfile := src.NewLinePragmaBase(src.MakePos(afile, 8, 1), "linedir", "linedir", 100, 1) + + var tests = []struct { + pos src.Pos + want string + }{ + {src.NoPos, "??:0"}, + {src.MakePos(afile, 1, 0), "a.go:1"}, + {src.MakePos(afile, 2, 0), "a.go:2"}, + {src.MakePos(bfile, 10, 4), "/foo/bar/b.go:10"}, + {src.MakePos(lfile, 10, 0), "linedir:102"}, // 102 == 100 + (10 - (7+1)) + } + + for _, test := range tests { + fileIndex, line := ctxt.getFileIndexAndLine(ctxt.PosTable.XPos(test.pos)) + + file := "??" + if fileIndex >= 0 { + file = ctxt.PosTable.FileTable()[fileIndex] + } + got := fmt.Sprintf("%s:%d", file, line) + + if got != test.want { + t.Errorf("ctxt.getFileSymbolAndLine(%v) = %q, want %q", test.pos, got, test.want) + } + } +} |