Skip to content

Commit 145caa8

Browse files
findleyrgopherbot
authored andcommitted
x/exp/typeparams: use regexp to match wanted result
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 <gobot@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> Auto-Submit: Robert Findley <rfindley@google.com> Reviewed-by: Robert Griesemer <gri@google.com>
1 parent fcb1a31 commit 145caa8

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

typeparams/normalize_test.go

+6-4
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import (
99
"go/parser"
1010
"go/token"
1111
"go/types"
12+
"regexp"
1213
"strings"
1314
"testing"
1415

@@ -36,7 +37,7 @@ func TestNormalTerms(t *testing.T) {
3637
{"package emptyintersection; type T[P interface{ ~int; string }] int", "", "empty type set"},
3738

3839
{"package embedded0; type T[P interface{ I }] int; type I interface { int }", "int", ""},
39-
{"package embedded1; type T[P interface{ I | string }] int; type I interface{ int | ~string }", "int|~string", ""},
40+
{"package embedded1; type T[P interface{ I | string }] int; type I interface{ int | ~string }", "int ?\\| ?~string", ""},
4041
{"package embedded2; type T[P interface{ I; string }] int; type I interface{ int | ~string }", "string", ""},
4142

4243
{"package named; type T[P C] int; type C interface{ ~int|int }", "~int", ""},
@@ -50,7 +51,7 @@ type B interface{ int|string }
5051
type C interface { ~string|~int }
5152
5253
type T[P interface{ A|B; C }] int
53-
`, "~string|int", ""},
54+
`, "~string ?\\| ?int", ""},
5455
}
5556

5657
for _, test := range tests {
@@ -94,8 +95,9 @@ type T[P interface{ A|B; C }] int
9495
qf := types.RelativeTo(pkg)
9596
got = types.TypeString(NewUnion(terms), qf)
9697
}
97-
if got != test.want {
98-
t.Errorf("StructuralTerms(%s) = %q, want %q", T, got, test.want)
98+
want := regexp.MustCompile(test.want)
99+
if !want.MatchString(got) {
100+
t.Errorf("NormalTerms(%s) = %q, want matching %q", T, got, test.want)
99101
}
100102
})
101103
}

0 commit comments

Comments
 (0)