File tree Expand file tree Collapse file tree 3 files changed +24
-10
lines changed Expand file tree Collapse file tree 3 files changed +24
-10
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ func TestNamespaceName(t *testing.T) {
22
22
require .EqualValues (t , "nsTest1.child" , nsTest1Child .FullName ())
23
23
}
24
24
25
- func TestNamespace (t * testing.T ) {
25
+ func TestIsNamespaceOf (t * testing.T ) {
26
26
require .True (t , nsTest0 .IsNamespaceOf (nsTestET0 ))
27
27
require .False (t , nsTest1 .IsNamespaceOf (nsTestET0 ))
28
28
require .False (t , nsTest0 .IsNamespaceOf (nsTestET1 ))
@@ -39,3 +39,16 @@ func TestSubNamespace(t *testing.T) {
39
39
require .True (t , nsTest1Child .IsNamespaceOf (nsTestChild1ET ))
40
40
require .True (t , nsTest1Child .IsNamespaceOf (nsTestChild1ETChild ))
41
41
}
42
+
43
+
44
+ func TestRootNamespace (t * testing.T ) {
45
+ require .Equal (t , nsTest1 , nsTestChild1ET .NewWithNoMessage ().Type ().RootNamespace ())
46
+ }
47
+
48
+ func TestNamespace (t * testing.T ) {
49
+ require .Equal (t , nsTest1Child , nsTestChild1ET .NewWithNoMessage ().Type ().Namespace ())
50
+ }
51
+
52
+ func TestSubTypeNamespaceFullName (t * testing.T ) {
53
+ require .Equal (t , "nsTest1.child" , nsTestChild1ETChild .Namespace ().FullName ())
54
+ }
Original file line number Diff line number Diff line change @@ -112,9 +112,18 @@ func (t *Type) FullName() string {
112
112
return t .fullName
113
113
}
114
114
115
+ // Namespace returns a namespace this type belongs to.
116
+ func (t * Type ) Namespace () Namespace {
117
+ return t .namespace
118
+ }
119
+
115
120
// RootNamespace returns a base namespace this type belongs to.
116
121
func (t * Type ) RootNamespace () Namespace {
117
- return t .namespace
122
+ n := t .namespace
123
+ for n .parent != nil {
124
+ n = * n .parent
125
+ }
126
+ return n
118
127
}
119
128
120
129
func (t * Type ) String () string {
Original file line number Diff line number Diff line change @@ -15,14 +15,6 @@ func TestSubTypeName(t *testing.T) {
15
15
require .Equal (t , "foo.bar.internal.wat" , testSubtype1 .FullName ())
16
16
}
17
17
18
- func TestRootNamespace (t * testing.T ) {
19
- require .Equal (t , testNamespace , testType .NewWithNoMessage ().Type ().RootNamespace ())
20
- }
21
-
22
- func TestSubTypeNamespace (t * testing.T ) {
23
- require .Equal (t , "foo" , testSubtype1 .RootNamespace ().FullName ())
24
- }
25
-
26
18
func TestErrorTypeCheck (t * testing.T ) {
27
19
require .True (t , testSubtype1 .IsOfType (testSubtype1 ))
28
20
require .False (t , testSubtype1 .IsOfType (NewNamespace ("a" ).NewType ("b" )))
You can’t perform that action at this time.
0 commit comments