mirror of
https://github.com/golang/go
synced 2025-05-25 15:00:09 +00:00
reflect: add more tests for Type.{CanSeq,CanSeq2}
For #71874.
Change-Id: I3850edfb3104305f3bf4847a73cdd826cc99837f
GitHub-Last-Rev: 574c1edb7a
GitHub-Pull-Request: golang/go#71890
Reviewed-on: https://go-review.googlesource.com/c/go/+/651775
Reviewed-by: Michael Knyszek <mknyszek@google.com>
Reviewed-by: Cherry Mui <cherryyz@google.com>
Auto-Submit: Dmitri Shuralyov <dmitshur@golang.org>
LUCI-TryBot-Result: Go LUCI <golang-scoped@luci-project-accounts.iam.gserviceaccount.com>
This commit is contained in:
src/reflect
@ -176,7 +176,7 @@ func TestValueSeq(t *testing.T) {
|
||||
t.Fatalf("should loop four times")
|
||||
}
|
||||
}},
|
||||
{"method", ValueOf(methodIter{}).Method(0), func(t *testing.T, s iter.Seq[Value]) {
|
||||
{"method", ValueOf(methodIter{}).MethodByName("Seq"), func(t *testing.T, s iter.Seq[Value]) {
|
||||
i := int64(0)
|
||||
for v := range s {
|
||||
if v.Int() != i {
|
||||
@ -323,7 +323,7 @@ func TestValueSeq2(t *testing.T) {
|
||||
t.Fatalf("should loop four times")
|
||||
}
|
||||
}},
|
||||
{"method", ValueOf(methodIter2{}).Method(0), func(t *testing.T, s iter.Seq2[Value, Value]) {
|
||||
{"method", ValueOf(methodIter2{}).MethodByName("Seq2"), func(t *testing.T, s iter.Seq2[Value, Value]) {
|
||||
i := int64(0)
|
||||
for v1, v2 := range s {
|
||||
if v1.Int() != i {
|
||||
@ -393,6 +393,9 @@ func (methodIter) Seq(yield func(int) bool) {
|
||||
}
|
||||
}
|
||||
|
||||
// For Type.CanSeq test.
|
||||
func (methodIter) NonSeq(yield func(int)) {}
|
||||
|
||||
// methodIter2 is a type from which we can derive a method
|
||||
// value that is an iter.Seq2.
|
||||
type methodIter2 struct{}
|
||||
@ -404,3 +407,6 @@ func (methodIter2) Seq2(yield func(int, int) bool) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// For Type.CanSeq2 test.
|
||||
func (methodIter2) NonSeq2(yield func(int, int)) {}
|
||||
|
@ -126,6 +126,8 @@ func TestType_CanSeq(t *testing.T) {
|
||||
}{
|
||||
{"func(func(int) bool)", reflect.TypeOf(func(func(int) bool) {}), true},
|
||||
{"func(func(int))", reflect.TypeOf(func(func(int)) {}), false},
|
||||
{"methodIter.Seq", reflect.ValueOf(methodIter{}).MethodByName("Seq").Type(), true},
|
||||
{"methodIter.NonSeq", reflect.ValueOf(methodIter{}).MethodByName("NonSeq").Type(), false},
|
||||
{"int64", reflect.TypeOf(int64(1)), true},
|
||||
{"uint64", reflect.TypeOf(uint64(1)), true},
|
||||
{"*[4]int", reflect.TypeOf(&[4]int{}), true},
|
||||
@ -151,6 +153,8 @@ func TestType_CanSeq2(t *testing.T) {
|
||||
}{
|
||||
{"func(func(int, int) bool)", reflect.TypeOf(func(func(int, int) bool) {}), true},
|
||||
{"func(func(int, int))", reflect.TypeOf(func(func(int, int)) {}), false},
|
||||
{"methodIter2.Seq2", reflect.ValueOf(methodIter2{}).MethodByName("Seq2").Type(), true},
|
||||
{"methodIter2.NonSeq2", reflect.ValueOf(methodIter2{}).MethodByName("NonSeq2").Type(), false},
|
||||
{"int64", reflect.TypeOf(int64(1)), false},
|
||||
{"uint64", reflect.TypeOf(uint64(1)), false},
|
||||
{"*[4]int", reflect.TypeOf(&[4]int{}), true},
|
||||
|
Reference in New Issue
Block a user