@@ -19,7 +19,7 @@ public void ProjectsAreAlwaysAccessible()
19
19
Assert . IsTrue ( AccessibilityCheck . IsAccessible ( null , null , null , projectDeclatation ) ) ;
20
20
}
21
21
22
- private static Declaration GetTestProject ( string name )
22
+ private static ProjectDeclaration GetTestProject ( string name )
23
23
{
24
24
var qualifiedProjectName = new QualifiedMemberName ( StubQualifiedModuleName ( ) , name ) ;
25
25
return new ProjectDeclaration ( qualifiedProjectName , name , false ) ;
@@ -43,7 +43,7 @@ public void ModulesCanBeAccessedFromWithinThemselves()
43
43
Assert . IsTrue ( AccessibilityCheck . IsAccessible ( projectDeclatation , moduleDeclatation , null , moduleDeclatation ) ) ;
44
44
}
45
45
46
- private static Declaration GetTestClassModule ( Declaration projectDeclatation , string name , bool isExposed = false )
46
+ private static ClassModuleDeclaration GetTestClassModule ( Declaration projectDeclatation , string name , bool isExposed = false )
47
47
{
48
48
var qualifiedClassModuleMemberName = new QualifiedMemberName ( StubQualifiedModuleName ( ) , name ) ;
49
49
var classModuleAttributes = new Rubberduck . Parsing . VBA . Attributes ( ) ;
@@ -101,7 +101,7 @@ public void NonPrivateProceduralModulesCanBeAccessedFromOtherProjects()
101
101
Assert . IsTrue ( AccessibilityCheck . IsAccessible ( callingProjectDeclatation , callingModuleDeclatation , null , calleeModuleDeclatation ) ) ;
102
102
}
103
103
104
- private static Declaration GetTestProceduralModule ( Declaration projectDeclatation , string name )
104
+ private static ProceduralModuleDeclaration GetTestProceduralModule ( Declaration projectDeclatation , string name )
105
105
{
106
106
var qualifiedClassModuleMemberName = new QualifiedMemberName ( StubQualifiedModuleName ( ) , name ) ;
107
107
var proceduralModuleDeclaration = new ProceduralModuleDeclaration ( qualifiedClassModuleMemberName , projectDeclatation , name , false , null , null ) ;
@@ -126,15 +126,30 @@ public void PrivateProceduresAreAccessibleFromTheEnclosingModule()
126
126
Assert . IsTrue ( AccessibilityCheck . IsAccessible ( projectDeclatation , moduleDeclatation , privateCallingFunctionDeclaration , privateCalleeFunctionDeclaration ) ) ;
127
127
}
128
128
129
- private static Declaration GetTestFunction ( Declaration moduleDeclatation , string name , Accessibility functionAccessibility )
129
+ private static FunctionDeclaration GetTestFunction ( Declaration moduleDeclatation , string name , Accessibility functionAccessibility )
130
130
{
131
131
var qualifiedFunctionMemberName = new QualifiedMemberName ( StubQualifiedModuleName ( ) , name ) ;
132
132
return new FunctionDeclaration ( qualifiedFunctionMemberName , moduleDeclatation , moduleDeclatation , "test" , null , "test" , functionAccessibility , null , Selection . Home , false , false , null , null ) ;
133
133
}
134
134
135
+ [ TestMethod ]
136
+ public void PrivateProceduresAreAccessibleIfTheyAreInAClassAboveTheEnclosingModuleOfTheCallerInTheClassHierarchy ( )
137
+ {
138
+ var projectDeclatation = GetTestProject ( "test_project" ) ;
139
+ var callingModule = GetTestClassModule ( projectDeclatation , "callingModule" ) ;
140
+ var privateCallingFunction = GetTestFunction ( callingModule , "callingFoo" , Accessibility . Private ) ;
141
+ var supertypeOfCallingModule = GetTestClassModule ( projectDeclatation , "callingModuleSuper" ) ;
142
+ callingModule . AddSupertype ( supertypeOfCallingModule ) ;
143
+ var supertypeOfSupertypeOfCallingModule = GetTestClassModule ( projectDeclatation , "callingModuleSuperSuper" ) ;
144
+ supertypeOfCallingModule . AddSupertype ( supertypeOfSupertypeOfCallingModule ) ;
145
+ var privateCalleeFunction = GetTestFunction ( supertypeOfSupertypeOfCallingModule , "calleeFoo" , Accessibility . Private ) ;
146
+
147
+ Assert . IsTrue ( AccessibilityCheck . IsAccessible ( projectDeclatation , callingModule , privateCallingFunction , privateCalleeFunction ) ) ;
148
+ }
149
+
135
150
136
151
[ TestMethod ]
137
- public void PrivateProceduresAreNotAcessibleFromOtherModules ( )
152
+ public void PrivateProceduresAreNotAcessibleFromOtherUnrelatedModules ( )
138
153
{
139
154
var projectDeclatation = GetTestProject ( "test_project" ) ;
140
155
var calleeModuleDeclatation = GetTestClassModule ( projectDeclatation , "callee_test_Module" ) ;
@@ -143,7 +158,7 @@ public void PrivateProceduresAreNotAcessibleFromOtherModules()
143
158
var callingFunctionDeclaration = GetTestFunction ( callingModuleDeclatation , "callingFoo" , Accessibility . Private ) ;
144
159
145
160
Assert . IsFalse ( AccessibilityCheck . IsAccessible ( projectDeclatation , callingModuleDeclatation , callingFunctionDeclaration , calleeFunctionDeclaration ) ) ;
146
- }
161
+ }
147
162
148
163
149
164
[ TestMethod ]
@@ -251,7 +266,23 @@ private static Declaration GetTestVariable(Declaration parentDeclatation, string
251
266
252
267
253
268
[ TestMethod ]
254
- public void PrivateInstanceVariablesAreNotAcessibleFromOtherModules ( )
269
+ public void PrivateInstanceVariablesAreAccessibleIfTheyAreInAClassAboveTheEnclosingModuleOfTheCallerInTheClassHierarchy ( )
270
+ {
271
+ var projectDeclatation = GetTestProject ( "test_project" ) ;
272
+ var callingModule = GetTestClassModule ( projectDeclatation , "callingModule" ) ;
273
+ var privateCallingFunction = GetTestFunction ( callingModule , "callingFoo" , Accessibility . Private ) ;
274
+ var supertypeOfCallingModule = GetTestClassModule ( projectDeclatation , "callingModuleSuper" ) ;
275
+ callingModule . AddSupertype ( supertypeOfCallingModule ) ;
276
+ var supertypeOfSupertypeOfCallingModule = GetTestClassModule ( projectDeclatation , "callingModuleSuperSuper" ) ;
277
+ supertypeOfCallingModule . AddSupertype ( supertypeOfSupertypeOfCallingModule ) ;
278
+ var privateCalleeInstanceVariable = GetTestVariable ( supertypeOfSupertypeOfCallingModule , "calleeFoo" , Accessibility . Private ) ;
279
+
280
+ Assert . IsTrue ( AccessibilityCheck . IsAccessible ( projectDeclatation , callingModule , privateCallingFunction , privateCalleeInstanceVariable ) ) ;
281
+ }
282
+
283
+
284
+ [ TestMethod ]
285
+ public void PrivateInstanceVariablesAreNotAcessibleFromOtherUnrelatedModules ( )
255
286
{
256
287
var projectDeclatation = GetTestProject ( "test_project" ) ;
257
288
var calleeModuleDeclatation = GetTestClassModule ( projectDeclatation , "callee_test_Module" ) ;
0 commit comments