mirror of
https://github.com/golang/go.git
synced 2025-12-08 06:10:04 +00: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:
parent
3a9fd99849
commit
09d82689ed
3 changed files with 82 additions and 10 deletions
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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)
|
||||
|
|
|
|||
|
|
@ -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])
|
||||
|
|
|
|||
Loadingβ¦
Add table
Add a link
Reference in a new issue