-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathtype_test.go
50 lines (45 loc) · 1.23 KB
/
type_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright 2018 The go-python Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package py
import "testing"
func TestIsSubType(t *testing.T) {
for _, test := range []struct {
a *Type
b *Type
want bool
}{
{ValueError, ValueError, true},
{ValueError, ExceptionType, true},
{ExceptionType, ValueError, false},
} {
got := test.a.IsSubtype(test.b)
if test.want != got {
t.Errorf("%v.IsSubtype(%v) want %v got %v", test.a.Name, test.b.Name, test.want, got)
}
}
}
func TestMro(t *testing.T) {
for _, test := range []struct {
t *Type
want []*Type
}{
{ObjectType, []*Type{ObjectType}},
{BaseException, []*Type{BaseException, ObjectType}},
{ExceptionType, []*Type{ExceptionType, BaseException, ObjectType}},
{ValueError, []*Type{ValueError, ExceptionType, BaseException, ObjectType}},
} {
got := test.t.Mro
if len(test.want) != len(got) {
t.Errorf("differing lengths: want %v, got %v", test.want, got)
} else {
for i := range got {
baseGot := got[i].(*Type)
baseWant := test.want[i]
if baseGot != baseWant {
t.Errorf("mro[%d] want %s got %s", i, baseWant.Name, baseGot.Name)
}
}
}
}
}