1
0
mirror of https://github.com/golang/go synced 2024-11-26 20:11:26 -07:00

[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])