@@ -53,7 +53,40 @@ public void AnnotationAlreadyPresent_AllowsMultiple_InApplicableAnnotations()
53
53
54
54
Assert . True ( applicableAnnotationNames . Contains ( "Ignore" ) ) ;
55
55
}
56
-
56
+
57
+ [ Test ]
58
+ public void AttributeAnnotation_NoAttributesContext_NoModule_NotInApplicableAnnotations ( )
59
+ {
60
+ var viewModel = TestViewModel ( DeclarationType . Variable , localScope : true ) ;
61
+ var applicableAnnotationNames = viewModel . ApplicableAnnotations
62
+ . Select ( annotation => annotation . Name )
63
+ . ToList ( ) ;
64
+
65
+ Assert . False ( applicableAnnotationNames . Contains ( "VariableDescription" ) ) ;
66
+ }
67
+
68
+ [ Test ]
69
+ public void AttributeAnnotation_NoAttributesContext_IsModule_InApplicableAnnotations ( )
70
+ {
71
+ var viewModel = TestViewModel ( DeclarationType . Module ) ;
72
+ var applicableAnnotationNames = viewModel . ApplicableAnnotations
73
+ . Select ( annotation => annotation . Name )
74
+ . ToList ( ) ;
75
+
76
+ Assert . True ( applicableAnnotationNames . Contains ( "Exposed" ) ) ;
77
+ }
78
+
79
+ [ Test ]
80
+ public void AttributeAnnotation_HasAttributesContext_NotInApplicableAnnotations ( )
81
+ {
82
+ var viewModel = TestViewModel ( DeclarationType . Variable , localScope : false ) ;
83
+ var applicableAnnotationNames = viewModel . ApplicableAnnotations
84
+ . Select ( annotation => annotation . Name )
85
+ . ToList ( ) ;
86
+
87
+ Assert . True ( applicableAnnotationNames . Contains ( "VariableDescription" ) ) ;
88
+ }
89
+
57
90
[ Test ]
58
91
public void AnnotationNull_Invalid ( )
59
92
{
@@ -264,10 +297,10 @@ public void DialogOK_SetsArguments()
264
297
}
265
298
266
299
267
- private AnnotateDeclarationViewModel TestViewModel ( DeclarationType targetDeclarationType , IAnnotation initialAnnotation = null )
300
+ private AnnotateDeclarationViewModel TestViewModel ( DeclarationType targetDeclarationType , IAnnotation initialAnnotation = null , bool localScope = false )
268
301
{
269
302
var argumentFactory = MockArgumentFactory ( ) . Object ;
270
- return TestViewModel ( targetDeclarationType , argumentFactory , initialAnnotation ) ;
303
+ return TestViewModel ( targetDeclarationType , argumentFactory , initialAnnotation , localScope ) ;
271
304
}
272
305
273
306
private Mock < IAnnotationArgumentViewModelFactory > MockArgumentFactory ( IReadOnlyList < bool > hasErrorSpecifications = null )
@@ -296,20 +329,21 @@ private Mock<IAnnotationArgumentViewModel> MockArgument(AnnotationArgumentType a
296
329
return mockArgument ;
297
330
}
298
331
299
- private AnnotateDeclarationViewModel TestViewModel ( DeclarationType targetDeclarationType , IAnnotationArgumentViewModelFactory argumentFactory , IAnnotation initialAnnotation = null )
332
+ private AnnotateDeclarationViewModel TestViewModel ( DeclarationType targetDeclarationType , IAnnotationArgumentViewModelFactory argumentFactory , IAnnotation initialAnnotation = null , bool localScope = false )
300
333
{
301
- var targetDeclaration = TestDeclaration ( targetDeclarationType ) ;
334
+ var targetDeclaration = TestDeclaration ( targetDeclarationType , localScope ) ;
302
335
var model = new AnnotateDeclarationModel ( targetDeclaration , initialAnnotation ) ;
303
336
return new AnnotateDeclarationViewModel ( model , _testAnnotations , argumentFactory ) ;
304
337
}
305
338
306
- private Declaration TestDeclaration ( DeclarationType targetDeclarationType )
339
+ private Declaration TestDeclaration ( DeclarationType targetDeclarationType , bool localScope = false )
307
340
{
308
341
const string code = @"
309
342
Public myVar As Variant
310
343
311
344
'@Ignore MissingMemberAnnotationInspection
312
345
Public Sub Foo
346
+ Dim bar As Variant
313
347
End Sub
314
348
315
349
'@DefaultMember
@@ -319,7 +353,15 @@ End Function
319
353
var vbe = MockVbeBuilder . BuildFromSingleModule ( code , ComponentType . ClassModule , out _ ) . Object ;
320
354
using ( var state = MockParser . CreateAndParse ( vbe ) )
321
355
{
322
- return state . DeclarationFinder . UserDeclarations ( targetDeclarationType ) . Single ( ) ;
356
+ if ( localScope )
357
+ {
358
+ return state . DeclarationFinder . UserDeclarations ( targetDeclarationType )
359
+ . Single ( declaration => declaration . ParentScopeDeclaration . DeclarationType . HasFlag ( DeclarationType . Member ) ) ;
360
+ }
361
+
362
+ return state . DeclarationFinder . UserDeclarations ( targetDeclarationType )
363
+ . Single ( declaration => declaration . DeclarationType . HasFlag ( DeclarationType . Module )
364
+ || declaration . ParentScopeDeclaration . DeclarationType . HasFlag ( DeclarationType . Module ) ) ;
323
365
}
324
366
}
325
367
0 commit comments