]> Cypherpunks repositories - gostls13.git/commitdiff
go/token: add TestRemovedFileFileReturnsNil test
authorMateusz Poliwczak <mpoliwczak34@gmail.com>
Mon, 22 Sep 2025 08:54:29 +0000 (10:54 +0200)
committerMateusz Poliwczak <mpoliwczak34@gmail.com>
Tue, 23 Sep 2025 18:49:54 +0000 (11:49 -0700)
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>
src/go/token/position_test.go

index b94647f78884568b9942423a58ef34f1f0aa09f5..c588a34d3df1e12398bf47a11ae484e06399290b 100644 (file)
@@ -621,3 +621,25 @@ func TestRemoveFileRace(t *testing.T) {
                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())
+               }
+       }
+}