[dev.typeparams] cmd/compile/internal/types2: add defined type to term/termlist tests

Follow-up on https://golang.org/cl/339596 .

Change-Id: Ifa249379df083f80176b9f99900be0bf12483f41
Reviewed-on: https://go-review.googlesource.com/c/go/+/339905
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Robert Findley <rfindley@google.com>
This commit is contained in:
Robert Griesemer 2021-08-04 22:22:54 -07:00
parent 3a9fd99849
commit 09d82689ed
3 changed files with 82 additions and 10 deletions

View file

@ -32,9 +32,11 @@ func TestTermlistString(t *testing.T) {
"𝓀",
"int",
"~int",
"myInt",
"βˆ… βˆͺ βˆ…",
"𝓀 βˆͺ 𝓀",
"βˆ… βˆͺ 𝓀 βˆͺ int",
"βˆ… βˆͺ 𝓀 βˆͺ int βˆͺ myInt",
} {
if got := maketl(want).String(); got != want {
t.Errorf("(%v).String() == %v", want, got)
@ -44,11 +46,13 @@ func TestTermlistString(t *testing.T) {
func TestTermlistIsEmpty(t *testing.T) {
for test, want := range map[string]bool{
"βˆ…": true,
"βˆ… βˆͺ βˆ…": true,
"βˆ… βˆͺ βˆ… βˆͺ 𝓀": false,
"𝓀": false,
"𝓀 βˆͺ int": false,
"βˆ…": true,
"βˆ… βˆͺ βˆ…": true,
"βˆ… βˆͺ βˆ… βˆͺ 𝓀": false,
"βˆ… βˆͺ βˆ… βˆͺ myInt": false,
"𝓀": false,
"𝓀 βˆͺ int": false,
"𝓀 βˆͺ myInt βˆͺ βˆ…": false,
} {
xl := maketl(test)
got := xl.isEmpty()
@ -63,9 +67,11 @@ func TestTermlistIsAll(t *testing.T) {
"βˆ…": false,
"βˆ… βˆͺ βˆ…": false,
"int βˆͺ ~string": false,
"~int βˆͺ myInt": false,
"βˆ… βˆͺ βˆ… βˆͺ 𝓀": true,
"𝓀": true,
"𝓀 βˆͺ int": true,
"myInt βˆͺ 𝓀": true,
} {
xl := maketl(test)
got := xl.isAll()
@ -82,10 +88,15 @@ func TestTermlistNorm(t *testing.T) {
{"βˆ…", "βˆ…"},
{"βˆ… βˆͺ βˆ…", "βˆ…"},
{"βˆ… βˆͺ int", "int"},
{"βˆ… βˆͺ myInt", "myInt"},
{"𝓀 βˆͺ int", "𝓀"},
{"𝓀 βˆͺ myInt", "𝓀"},
{"int βˆͺ myInt", "int βˆͺ myInt"},
{"~int βˆͺ int", "~int"},
{"~int βˆͺ myInt", "~int"},
{"int βˆͺ ~string βˆͺ int", "int βˆͺ ~string"},
{"~int βˆͺ string βˆͺ 𝓀 βˆͺ ~string βˆͺ int", "𝓀"},
{"~int βˆͺ string βˆͺ myInt βˆͺ ~string βˆͺ int", "~int βˆͺ ~string"},
} {
xl := maketl(test.xl)
got := maketl(test.xl).norm()
@ -108,8 +119,10 @@ func TestTermlistStructuralType(t *testing.T) {
"βˆ…": "nil",
"𝓀": "nil",
"int": "int",
"myInt": "myInt",
"~int": "int",
"~int βˆͺ string": "nil",
"~int βˆͺ myInt": "int",
"βˆ… βˆͺ int": "int",
"βˆ… βˆͺ ~int": "int",
"βˆ… βˆͺ ~int βˆͺ string": "nil",
@ -133,10 +146,14 @@ func TestTermlistUnion(t *testing.T) {
{"𝓀", "~int", "𝓀"},
{"int", "~int", "~int"},
{"int", "string", "int βˆͺ string"},
{"int", "myInt", "int βˆͺ myInt"},
{"~int", "myInt", "~int"},
{"int βˆͺ string", "~string", "int βˆͺ ~string"},
{"~int βˆͺ string", "~string βˆͺ int", "~int βˆͺ ~string"},
{"~int βˆͺ string βˆͺ βˆ…", "~string βˆͺ int", "~int βˆͺ ~string"},
{"~int βˆͺ myInt βˆͺ βˆ…", "~string βˆͺ int", "~int βˆͺ ~string"},
{"~int βˆͺ string βˆͺ 𝓀", "~string βˆͺ int", "𝓀"},
{"~int βˆͺ string βˆͺ myInt", "~string βˆͺ int", "~int βˆͺ ~string"},
} {
xl := maketl(test.xl)
yl := maketl(test.yl)
@ -155,13 +172,19 @@ func TestTermlistIntersect(t *testing.T) {
{"βˆ…", "βˆ…", "βˆ…"},
{"βˆ…", "𝓀", "βˆ…"},
{"βˆ…", "int", "βˆ…"},
{"βˆ…", "myInt", "βˆ…"},
{"𝓀", "~int", "~int"},
{"𝓀", "myInt", "myInt"},
{"int", "~int", "int"},
{"int", "string", "βˆ…"},
{"int", "myInt", "βˆ…"},
{"~int", "myInt", "myInt"},
{"int βˆͺ string", "~string", "string"},
{"~int βˆͺ string", "~string βˆͺ int", "int βˆͺ string"},
{"~int βˆͺ string βˆͺ βˆ…", "~string βˆͺ int", "int βˆͺ string"},
{"~int βˆͺ myInt βˆͺ βˆ…", "~string βˆͺ int", "int"},
{"~int βˆͺ string βˆͺ 𝓀", "~string βˆͺ int", "int βˆͺ ~string"},
{"~int βˆͺ string βˆͺ myInt", "~string βˆͺ int", "int βˆͺ string"},
} {
xl := maketl(test.xl)
yl := maketl(test.yl)
@ -182,7 +205,9 @@ func TestTermlistEqual(t *testing.T) {
{"𝓀", "𝓀", true},
{"𝓀 βˆͺ int", "𝓀", true},
{"𝓀 βˆͺ int", "string βˆͺ 𝓀", true},
{"𝓀 βˆͺ myInt", "string βˆͺ 𝓀", true},
{"int βˆͺ ~string", "string βˆͺ int", false},
{"~int βˆͺ string", "string βˆͺ myInt", false},
{"int βˆͺ ~string βˆͺ βˆ…", "string βˆͺ int βˆͺ ~string", true},
} {
xl := maketl(test.xl)
@ -204,10 +229,12 @@ func TestTermlistIncludes(t *testing.T) {
{"~int", "int", true},
{"int", "string", false},
{"~int", "string", false},
{"~int", "myInt", true},
{"int βˆͺ string", "string", true},
{"~int βˆͺ string", "int", true},
{"~int βˆͺ string βˆͺ βˆ…", "string", true},
{"~string βˆͺ βˆ… βˆͺ 𝓀", "int", true},
{"~int βˆͺ string", "myInt", true},
{"~int βˆͺ myInt βˆͺ βˆ…", "myInt", true},
{"myInt βˆͺ βˆ… βˆͺ 𝓀", "int", true},
} {
xl := maketl(test.xl)
yl := testTerm(test.typ).typ
@ -230,16 +257,20 @@ func TestTermlistSupersetOf(t *testing.T) {
{"𝓀", "𝓀", true},
{"𝓀", "int", true},
{"𝓀", "~int", true},
{"𝓀", "myInt", true},
{"~int", "int", true},
{"~int", "~int", true},
{"~int", "myInt", true},
{"int", "~int", false},
{"myInt", "~int", false},
{"int", "string", false},
{"~int", "string", false},
{"int βˆͺ string", "string", true},
{"int βˆͺ string", "~string", false},
{"~int βˆͺ string", "int", true},
{"~int βˆͺ string", "myInt", true},
{"~int βˆͺ string βˆͺ βˆ…", "string", true},
{"~string βˆͺ βˆ… βˆͺ 𝓀", "int", true},
{"~string βˆͺ βˆ… βˆͺ 𝓀", "myInt", true},
} {
xl := maketl(test.xl)
y := testTerm(test.typ)
@ -261,12 +292,16 @@ func TestTermlistSubsetOf(t *testing.T) {
{"𝓀", "𝓀", true},
{"int", "int βˆͺ string", true},
{"~int", "int βˆͺ string", false},
{"~int", "myInt βˆͺ string", false},
{"myInt", "~int βˆͺ string", true},
{"~int", "string βˆͺ string βˆͺ int βˆͺ ~int", true},
{"myInt", "string βˆͺ string βˆͺ ~int", true},
{"int βˆͺ string", "string", false},
{"int βˆͺ string", "string βˆͺ int", true},
{"int βˆͺ ~string", "string βˆͺ int", false},
{"int βˆͺ ~string", "string βˆͺ int βˆͺ 𝓀", true},
{"myInt βˆͺ ~string", "string βˆͺ int βˆͺ 𝓀", true},
{"int βˆͺ ~string", "string βˆͺ int βˆͺ βˆ… βˆͺ string", false},
{"int βˆͺ myInt", "string βˆͺ ~int βˆͺ βˆ… βˆͺ string", true},
} {
xl := maketl(test.xl)
yl := maketl(test.yl)

View file

@ -151,6 +151,9 @@ func (x *term) subsetOf(y *term) bool {
// disjoint reports whether x ∩ y == βˆ….
// x.typ and y.typ must not be nil.
func (x *term) disjoint(y *term) bool {
if debug && (x.typ == nil || y.typ == nil) {
panic("invalid argument(s)")
}
ux := x.typ
if y.tilde {
ux = under(ux)

View file

@ -9,6 +9,11 @@ import (
"testing"
)
var myInt = func() Type {
tname := NewTypeName(nopos, nil, "myInt", nil)
return NewNamed(tname, Typ[Int], nil)
}()
var testTerms = map[string]*term{
"βˆ…": nil,
"𝓀": {},
@ -16,7 +21,7 @@ var testTerms = map[string]*term{
"~int": {true, Typ[Int]},
"string": {false, Typ[String]},
"~string": {true, Typ[String]},
// TODO(gri) add a defined type
"myInt": {false, myInt},
}
func TestTermString(t *testing.T) {
@ -49,12 +54,16 @@ func TestTermEqual(t *testing.T) {
"𝓀 𝓀 T",
"int int T",
"~int ~int T",
"myInt myInt T",
"βˆ… 𝓀 F",
"βˆ… int F",
"βˆ… ~int F",
"𝓀 int F",
"𝓀 ~int F",
"𝓀 myInt F",
"int ~int F",
"int myInt F",
"~int myInt F",
} {
args := split(test, 3)
x := testTerm(args[0])
@ -77,25 +86,33 @@ func TestTermUnion(t *testing.T) {
"βˆ… 𝓀 𝓀 βˆ…",
"βˆ… int int βˆ…",
"βˆ… ~int ~int βˆ…",
"βˆ… myInt myInt βˆ…",
"𝓀 𝓀 𝓀 βˆ…",
"𝓀 int 𝓀 βˆ…",
"𝓀 ~int 𝓀 βˆ…",
"𝓀 myInt 𝓀 βˆ…",
"int int int βˆ…",
"int ~int ~int βˆ…",
"int string int string",
"int ~string int ~string",
"int myInt int myInt",
"~int ~string ~int ~string",
"~int myInt ~int βˆ…",
// union is symmetric, but the result order isn't - repeat symmetric cases explictly
"𝓀 βˆ… 𝓀 βˆ…",
"int βˆ… int βˆ…",
"~int βˆ… ~int βˆ…",
"myInt βˆ… myInt βˆ…",
"int 𝓀 𝓀 βˆ…",
"~int 𝓀 𝓀 βˆ…",
"myInt 𝓀 𝓀 βˆ…",
"~int int ~int βˆ…",
"string int string int",
"~string int ~string int",
"myInt int myInt int",
"~string ~int ~string ~int",
"myInt ~int ~int βˆ…",
} {
args := split(test, 4)
x := testTerm(args[0])
@ -114,14 +131,18 @@ func TestTermIntersection(t *testing.T) {
"βˆ… 𝓀 βˆ…",
"βˆ… int βˆ…",
"βˆ… ~int βˆ…",
"βˆ… myInt βˆ…",
"𝓀 𝓀 𝓀",
"𝓀 int int",
"𝓀 ~int ~int",
"𝓀 myInt myInt",
"int int int",
"int ~int int",
"int string βˆ…",
"int ~string βˆ…",
"int string βˆ…",
"~int ~string βˆ…",
"~int myInt myInt",
} {
args := split(test, 3)
x := testTerm(args[0])
@ -144,8 +165,10 @@ func TestTermIncludes(t *testing.T) {
"𝓀 int T",
"int int T",
"~int int T",
"~int myInt T",
"string int F",
"~string int F",
"myInt int F",
} {
args := split(test, 3)
x := testTerm(args[0])
@ -163,12 +186,19 @@ func TestTermSubsetOf(t *testing.T) {
"𝓀 𝓀 T",
"int int T",
"~int ~int T",
"myInt myInt T",
"βˆ… 𝓀 T",
"βˆ… int T",
"βˆ… ~int T",
"βˆ… myInt T",
"𝓀 int F",
"𝓀 ~int F",
"𝓀 myInt F",
"int ~int T",
"int myInt F",
"~int myInt F",
"myInt int F",
"myInt ~int T",
} {
args := split(test, 3)
x := testTerm(args[0])
@ -187,7 +217,11 @@ func TestTermDisjoint(t *testing.T) {
"int ~int F",
"int string T",
"int ~string T",
"int myInt T",
"~int ~string T",
"~int myInt F",
"string myInt T",
"~string myInt T",
} {
args := split(test, 3)
x := testTerm(args[0])