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) {
2222require .EqualValues (t , "nsTest1.child" , nsTest1Child .FullName ())
2323}
2424
25- func TestNamespace (t * testing.T ) {
25+ func TestIsNamespaceOf (t * testing.T ) {
2626require .True (t , nsTest0 .IsNamespaceOf (nsTestET0 ))
2727require .False (t , nsTest1 .IsNamespaceOf (nsTestET0 ))
2828require .False (t , nsTest0 .IsNamespaceOf (nsTestET1 ))
@@ -39,3 +39,16 @@ func TestSubNamespace(t *testing.T) {
3939require .True (t , nsTest1Child .IsNamespaceOf (nsTestChild1ET ))
4040require .True (t , nsTest1Child .IsNamespaceOf (nsTestChild1ETChild ))
4141}
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 {
112112return t .fullName
113113}
114114
115+ // Namespace returns a namespace this type belongs to.
116+ func (t * Type ) Namespace () Namespace {
117+ return t .namespace
118+ }
119+
115120// RootNamespace returns a base namespace this type belongs to.
116121func (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
118127}
119128
120129func (t * Type ) String () string {
Original file line number Diff line number Diff line change @@ -15,14 +15,6 @@ func TestSubTypeName(t *testing.T) {
1515require .Equal (t , "foo.bar.internal.wat" , testSubtype1 .FullName ())
1616}
1717
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-
2618func TestErrorTypeCheck (t * testing.T ) {
2719require .True (t , testSubtype1 .IsOfType (testSubtype1 ))
2820require .False (t , testSubtype1 .IsOfType (NewNamespace ("a" ).NewType ("b" )))
You can’t perform that action at this time.
0 commit comments