mirror of https://github.com/golang/go.git
x/tools/internal/typeparams: use regexp to match wanted result
CL 410955 changes printing of unions which breaks two typeparams tests. Use regexp matching and adjust the wanted results accordingly. For golang/go#53279. For golang/go#54822. Change-Id: I7060df47d36ce3069570237dafff024aaad637a5 Reviewed-on: https://go-review.googlesource.com/c/tools/+/428055 Auto-Submit: Robert Griesemer <gri@google.com> Reviewed-by: Robert Griesemer <gri@google.com> TryBot-Result: Gopher Robot <gobot@golang.org> Reviewed-by: Robert Findley <rfindley@google.com> gopls-CI: kokoro <noreply+kokoro@google.com> Run-TryBot: Robert Griesemer <gri@google.com>
This commit is contained in:
parent
be9eab19b4
commit
6a585a2bf9
|
|
@ -9,6 +9,7 @@ import (
|
|||
"go/parser"
|
||||
"go/token"
|
||||
"go/types"
|
||||
"regexp"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
|
|
@ -38,7 +39,7 @@ func TestStructuralTerms(t *testing.T) {
|
|||
{"package emptyintersection; type T[P interface{ ~int; string }] int", "", "empty type set"},
|
||||
|
||||
{"package embedded0; type T[P interface{ I }] int; type I interface { int }", "int", ""},
|
||||
{"package embedded1; type T[P interface{ I | string }] int; type I interface{ int | ~string }", "int|~string", ""},
|
||||
{"package embedded1; type T[P interface{ I | string }] int; type I interface{ int | ~string }", "int ?\\| ?~string", ""},
|
||||
{"package embedded2; type T[P interface{ I; string }] int; type I interface{ int | ~string }", "string", ""},
|
||||
|
||||
{"package named; type T[P C] int; type C interface{ ~int|int }", "~int", ""},
|
||||
|
|
@ -52,7 +53,7 @@ type B interface{ int|string }
|
|||
type C interface { ~string|~int }
|
||||
|
||||
type T[P interface{ A|B; C }] int
|
||||
`, "~string|int", ""},
|
||||
`, "~string ?\\| ?int", ""},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
|
|
@ -96,7 +97,8 @@ type T[P interface{ A|B; C }] int
|
|||
qf := types.RelativeTo(pkg)
|
||||
got = types.TypeString(NewUnion(terms), qf)
|
||||
}
|
||||
if got != test.want {
|
||||
want := regexp.MustCompile(test.want)
|
||||
if !want.MatchString(got) {
|
||||
t.Errorf("StructuralTerms(%s) = %q, want %q", T, got, test.want)
|
||||
}
|
||||
})
|
||||
|
|
|
|||
Loading…
Reference in New Issue