mirror of
https://github.com/golang/go.git
synced 2026-04-02 17:30:01 +09:00
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>
This commit is contained in:
committed by
Gopher Robot
parent
9697bd96bc
commit
4e693d1ec5
1
api/next/76285.txt
Normal file
1
api/next/76285.txt
Normal file
@@ -0,0 +1 @@
|
||||
pkg go/token, method (*File) String() string #76285
|
||||
1
doc/next/6-stdlib/99-minor/go/token/76285.md
Normal file
1
doc/next/6-stdlib/99-minor/go/token/76285.md
Normal file
@@ -0,0 +1 @@
|
||||
[File] now has a String method.
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user