go/token: add TestRemovedFileFileReturnsNil test

While debugging test issue in the previous CL i noted that we don't have
a proper test for RemoveFile.

Change-Id: I6a6a6964426ed3cf6725a58ec377686c2900c626
Reviewed-on: https://go-review.googlesource.com/c/go/+/705757
Reviewed-by: Alan Donovan <adonovan@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
Reviewed-by: Junyang Shao <shaojunyang@google.com>
This commit is contained in:
Mateusz Poliwczak 2025-09-22 10:54:29 +02:00
parent 902dc27ae9
commit 74cc463f9e

View file

@ -621,3 +621,25 @@ func TestRemoveFileRace(t *testing.T) {
start <- struct{}{} start <- struct{}{}
} }
} }
func TestRemovedFileFileReturnsNil(t *testing.T) {
fset := NewFileSet()
// Create bunch of files.
var files []*File
for i := range 1000 {
f := fset.AddFile("f", -1, (i+1)*100)
files = append(files, f)
}
rand.Shuffle(len(files), func(i, j int) {
files[i], files[j] = files[j], files[i]
})
for _, f := range files {
fset.RemoveFile(f)
if got := fset.File(Pos(f.Base()) + 10); got != nil {
t.Fatalf("file was not removed correctly; got file with base: %v", got.Base())
}
}
}