aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--api/next/76285.txt1
-rw-r--r--doc/next/6-stdlib/99-minor/go/token/76285.md1
-rw-r--r--src/go/token/position.go5
-rw-r--r--src/go/token/position_test.go8
4 files changed, 15 insertions, 0 deletions
diff --git a/api/next/76285.txt b/api/next/76285.txt
new file mode 100644
index 0000000000..afe2314bd4
--- /dev/null
+++ b/api/next/76285.txt
@@ -0,0 +1 @@
+pkg go/token, method (*File) String() string #76285
diff --git a/doc/next/6-stdlib/99-minor/go/token/76285.md b/doc/next/6-stdlib/99-minor/go/token/76285.md
new file mode 100644
index 0000000000..570074214b
--- /dev/null
+++ b/doc/next/6-stdlib/99-minor/go/token/76285.md
@@ -0,0 +1 @@
+[File] now has a String method.
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)
+ }
+}