diff options
| author | Alan Donovan <adonovan@google.com> | 2026-02-09 10:33:22 -0500 |
|---|---|---|
| committer | Gopher Robot <gobot@golang.org> | 2026-02-23 07:48:58 -0800 |
| commit | 4e693d1ec52c86b262ac23f0d6cee6b60fef4fb0 (patch) | |
| tree | 6a60314dd420a704bda88dc10fc07f7723a0d8f4 /src | |
| parent | 9697bd96bcc98cbe201d0f57033d9f2dab66b9f6 (diff) | |
| download | go-4e693d1ec52c86b262ac23f0d6cee6b60fef4fb0.tar.xz | |
go/token: add File.String method
It returns a brief, unspecified, human-readable description
of the File.
+ test, doc, relnote
Fixes #76285
Change-Id: I8b0705cf20eaac095bc9dfba7f1181774544f02c
Reviewed-on: https://go-review.googlesource.com/c/go/+/743280
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Auto-Submit: Alan Donovan <adonovan@google.com>
Diffstat (limited to 'src')
| -rw-r--r-- | src/go/token/position.go | 5 | ||||
| -rw-r--r-- | src/go/token/position_test.go | 8 |
2 files changed, 13 insertions, 0 deletions
diff --git a/src/go/token/position.go b/src/go/token/position.go index 37a468012d..4fb8031eea 100644 --- a/src/go/token/position.go +++ b/src/go/token/position.go @@ -112,6 +112,11 @@ type File struct { infos []lineInfo } +// String returns a brief description of the File. +func (f *File) String() string { + return fmt.Sprintf("%s(%d-%d)", f.Name(), f.Base(), f.End()) +} + // Name returns the file name of file f as registered with AddFile. func (f *File) Name() string { return f.name diff --git a/src/go/token/position_test.go b/src/go/token/position_test.go index 3d02068ebf..7971006ce5 100644 --- a/src/go/token/position_test.go +++ b/src/go/token/position_test.go @@ -651,3 +651,11 @@ func TestFile_End(t *testing.T) { t.Errorf("Base, End = %s, want %s", got, want) } } + +func TestFile_String(t *testing.T) { + f := NewFileSet().AddFile("a.go", 100, 42) + got := f.String() + if want := "a.go(100-142)"; got != want { + t.Errorf("String = %q, want %q", got, want) + } +} |
