]> Cypherpunks repositories - gostls13.git/commitdiff
go/types: add tests for AssignableTo and ConvertibleTo
authorRob Findley <rfindley@google.com>
Wed, 1 Jul 2020 22:10:02 +0000 (18:10 -0400)
committerRobert Findley <rfindley@google.com>
Mon, 24 Aug 2020 16:35:21 +0000 (16:35 +0000)
These exported functions are mostly trivial wrappers, but do make
certain assumptions about how the underlying Checker APIs can be called.
Add some simple tests.

Change-Id: I68e9ae875353c12d118ec961a6f3834385fbbb97
Reviewed-on: https://go-review.googlesource.com/c/go/+/241262
Run-TryBot: Robert Findley <rfindley@google.com>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Robert Griesemer <gri@golang.org>
src/go/types/api_test.go

index fe3950a52d87c0e66465fcbd6089bd210a1d8be5..798c09bbffd1dece1a7330f153850559b8643846 100644 (file)
@@ -1232,6 +1232,41 @@ func F(){
        }
 }
 
+func TestConvertibleTo(t *testing.T) {
+       for _, test := range []struct {
+               v, t Type
+               want bool
+       }{
+               {Typ[Int], Typ[Int], true},
+               {Typ[Int], Typ[Float32], true},
+               {newDefined(Typ[Int]), Typ[Int], true},
+               {newDefined(new(Struct)), new(Struct), true},
+               {newDefined(Typ[Int]), new(Struct), false},
+               {Typ[UntypedInt], Typ[Int], true},
+       } {
+               if got := ConvertibleTo(test.v, test.t); got != test.want {
+                       t.Errorf("ConvertibleTo(%v, %v) = %t, want %t", test.v, test.t, got, test.want)
+               }
+       }
+}
+
+func TestAssignableTo(t *testing.T) {
+       for _, test := range []struct {
+               v, t Type
+               want bool
+       }{
+               {Typ[Int], Typ[Int], true},
+               {Typ[Int], Typ[Float32], false},
+               {newDefined(Typ[Int]), Typ[Int], false},
+               {newDefined(new(Struct)), new(Struct), true},
+               {Typ[UntypedBool], Typ[Bool], true},
+       } {
+               if got := AssignableTo(test.v, test.t); got != test.want {
+                       t.Errorf("AssignableTo(%v, %v) = %t, want %t", test.v, test.t, got, test.want)
+               }
+       }
+}
+
 func TestIdentical_issue15173(t *testing.T) {
        // Identical should allow nil arguments and be symmetric.
        for _, test := range []struct {