Skip to content

Commit

Permalink
x/exp/typeparams: use regexp to match wanted result
Browse files Browse the repository at this point in the history
This is a port of CL 428055 to the external x/exp/typeparams package.
Also fix a stale test error message.

Fixes golang/go#54903

Change-Id: Iafa0df489e1d2bf7ce43f2e7854d87b2635e1f42
Reviewed-on: https://go-review.googlesource.com/c/exp/+/428875
TryBot-Result: Gopher Robot <[email protected]>
Run-TryBot: Robert Findley <[email protected]>
Auto-Submit: Robert Findley <[email protected]>
Reviewed-by: Robert Griesemer <[email protected]>
  • Loading branch information
findleyr authored and gopherbot committed Sep 7, 2022
1 parent fcb1a31 commit 145caa8
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions typeparams/normalize_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"go/parser"
"go/token"
"go/types"
"regexp"
"strings"
"testing"

Expand Down Expand Up @@ -36,7 +37,7 @@ func TestNormalTerms(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", ""},
Expand All @@ -50,7 +51,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 {
Expand Down Expand Up @@ -94,8 +95,9 @@ type T[P interface{ A|B; C }] int
qf := types.RelativeTo(pkg)
got = types.TypeString(NewUnion(terms), qf)
}
if got != test.want {
t.Errorf("StructuralTerms(%s) = %q, want %q", T, got, test.want)
want := regexp.MustCompile(test.want)
if !want.MatchString(got) {
t.Errorf("NormalTerms(%s) = %q, want matching %q", T, got, test.want)
}
})
}
Expand Down

0 comments on commit 145caa8

Please sign in to comment.