]> Cypherpunks repositories - gostls13.git/commitdiff
reflect: add more tests for Type.{CanSeq,CanSeq2}
authorJes Cok <xigua67damn@gmail.com>
Fri, 28 Feb 2025 00:52:53 +0000 (00:52 +0000)
committerGopher Robot <gobot@golang.org>
Fri, 28 Feb 2025 19:09:39 +0000 (11:09 -0800)
For #71874.

Change-Id: I3850edfb3104305f3bf4847a73cdd826cc99837f
GitHub-Last-Rev: 574c1edb7a6152c71891fab011ac0aaeca955fc8
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>

src/reflect/iter_test.go
src/reflect/type_test.go

index 3a10af22f23e653703cb04a84348e8da5f64c9e8..668d66528028011a8e8c2be55b7b8a3fb177b734 100644 (file)
@@ -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)) {}
index 51abc0776cd4f13a5c9b9ce21247573b50502d26..fc76a4fb9858e5f78b2bee7a7f97fe70b5952f91 100644 (file)
@@ -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},