diff options
| author | Rob Findley <rfindley@google.com> | 2025-11-18 22:14:18 +0000 |
|---|---|---|
| committer | Robert Findley <rfindley@google.com> | 2025-11-18 14:36:18 -0800 |
| commit | aaa56eca6e7bcd7644b986f843498a389ac39297 (patch) | |
| tree | 64ec53a7c1bc78b6acbfdf9bb6c8544d807db025 | |
| parent | 519903f45a28ca8a24ca36f9ac86eb2e24cc3af2 (diff) | |
| download | go-x-pkgsite-aaa56eca6e7bcd7644b986f843498a389ac39297.tar.xz | |
internal/godoc: fix codec generation test
ast.BasicLit has a new field. While we figure out what to do with this,
update the test to pass.
Updates golang/go#76350
Change-Id: Iaffabd1335dd17143d08fcd677c0f4ed6296a50f
Reviewed-on: https://go-review.googlesource.com/c/pkgsite/+/721800
Reviewed-by: Ethan Lee <ethanalee@google.com>
Auto-Submit: Robert Findley <rfindley@google.com>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
TryBot-Bypass: Robert Findley <rfindley@google.com>
| -rw-r--r-- | internal/godoc/codec/generate_test.go | 14 | ||||
| -rw-r--r-- | internal/godoc/codec/testdata/struct.go | 21 |
2 files changed, 22 insertions, 13 deletions
diff --git a/internal/godoc/codec/generate_test.go b/internal/godoc/codec/generate_test.go index 984a32fb..dfa5b798 100644 --- a/internal/godoc/codec/generate_test.go +++ b/internal/godoc/codec/generate_test.go @@ -7,7 +7,6 @@ package codec import ( "bytes" "flag" - "go/ast" "go/token" "io" "reflect" @@ -46,7 +45,18 @@ func TestGoName(t *testing.T) { func TestGenerate(t *testing.T) { testGenerate(t, "slice", [][]int(nil)) testGenerate(t, "map", map[string]bool(nil)) - testGenerate(t, "struct", ast.BasicLit{}) + testGenerate(t, "struct", BasicLit{}) +} + +// Copy of ast.BasicLit before ValueEnd was added in golang/go#76031. +// This largely preserves the previous test data. +// +// See also golang/go#76350: we should figure out what to do with new fields, +// in general. In this case we can probably just safely skip the field. +type BasicLit struct { + ValuePos token.Pos // literal position + Kind token.Token + Value string } func testGenerate(t *testing.T, name string, x any) { diff --git a/internal/godoc/codec/testdata/struct.go b/internal/godoc/codec/testdata/struct.go index d102fc95..ad9becb1 100644 --- a/internal/godoc/codec/testdata/struct.go +++ b/internal/godoc/codec/testdata/struct.go @@ -9,14 +9,13 @@ package somepkg import ( - "go/ast" "go/token" "golang.org/x/pkgsite/internal/godoc/codec" ) -// Fields of ast_BasicLit: ValuePos Kind Value +// Fields of codec_BasicLit: ValuePos Kind Value -func encode_ast_BasicLit(e *codec.Encoder, x *ast.BasicLit) { +func encode_codec_BasicLit(e *codec.Encoder, x *codec.BasicLit) { if !e.StartStruct(x == nil, x) { return } @@ -35,16 +34,16 @@ func encode_ast_BasicLit(e *codec.Encoder, x *ast.BasicLit) { e.EndStruct() } -func decode_ast_BasicLit(d *codec.Decoder, p **ast.BasicLit) { +func decode_codec_BasicLit(d *codec.Decoder, p **codec.BasicLit) { proceed, ref := d.StartStruct() if !proceed { return } if ref != nil { - *p = ref.(*ast.BasicLit) + *p = ref.(*codec.BasicLit) return } - var x ast.BasicLit + var x codec.BasicLit d.StoreRef(&x) for { n := d.NextStructField() @@ -59,18 +58,18 @@ func decode_ast_BasicLit(d *codec.Decoder, p **ast.BasicLit) { case 2: x.Value = d.DecodeString() default: - d.UnknownField("ast.BasicLit", n) + d.UnknownField("codec.BasicLit", n) } *p = &x } } func init() { - codec.Register(&ast.BasicLit{}, - func(e *codec.Encoder, x any) { encode_ast_BasicLit(e, x.(*ast.BasicLit)) }, + codec.Register(&codec.BasicLit{}, + func(e *codec.Encoder, x any) { encode_codec_BasicLit(e, x.(*codec.BasicLit)) }, func(d *codec.Decoder) any { - var x *ast.BasicLit - decode_ast_BasicLit(d, &x) + var x *codec.BasicLit + decode_codec_BasicLit(d, &x) return x }) } |
