1
+ using System . Linq ;
2
+ using NUnit . Framework ;
3
+ using Rubberduck . Parsing . Symbols ;
4
+ using RubberduckTests . Mocks ;
5
+
6
+ namespace RubberduckTests . Annotations
7
+ {
8
+ [ TestFixture ]
9
+ public class DeclarationsListenerAnnotationsTests
10
+ {
11
+ [ Test ]
12
+ public void AnnotationsAboveMemberGetScopedToMember_NotFirstMember ( )
13
+ {
14
+ const string inputCode =
15
+ @"
16
+ Public Sub Foo()
17
+ End Sub
18
+ '@TestMethod
19
+ '@Enumerator 17, 12 @DefaultMember
20
+ Public Function Bar() As Variant
21
+ End Function" ;
22
+ var vbe = MockVbeBuilder . BuildFromSingleStandardModule ( inputCode , out _ ) ;
23
+ using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
24
+ {
25
+ var barDeclaration = state . DeclarationFinder . UserDeclarations ( DeclarationType . Function ) . Single ( ) ;
26
+
27
+ var expectedAnnotationCount = 3 ;
28
+ var actualAnnotationCount = barDeclaration . Annotations . Count ( ) ;
29
+
30
+ Assert . AreEqual ( expectedAnnotationCount , actualAnnotationCount ) ;
31
+ }
32
+ }
33
+
34
+ [ Test ]
35
+ public void AnnotationsAboveMemberGetScopedToMember_FirstMember ( )
36
+ {
37
+ const string inputCode =
38
+ @"
39
+ '@TestMethod
40
+ '@Enumerator 17, 12 @DefaultMember
41
+ Public Sub Foo()
42
+ End Sub
43
+
44
+ Public Function Bar() As Variant
45
+ End Function" ;
46
+ var vbe = MockVbeBuilder . BuildFromSingleStandardModule ( inputCode , out _ ) ;
47
+ using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
48
+ {
49
+ var fooDeclaration = state . DeclarationFinder . UserDeclarations ( DeclarationType . Procedure ) . Single ( ) ;
50
+
51
+ var expectedAnnotationCount = 3 ;
52
+ var actualAnnotationCount = fooDeclaration . Annotations . Count ( ) ;
53
+
54
+ Assert . AreEqual ( expectedAnnotationCount , actualAnnotationCount ) ;
55
+ }
56
+ }
57
+
58
+ [ Test ]
59
+ public void LineContinuedAnnotationsAboveMemberGetScopedToMember_NotFirstMember ( )
60
+ {
61
+ const string inputCode =
62
+ @"
63
+ Public Sub Foo()
64
+ End Sub
65
+ '@TestMethod _
66
+
67
+ '@Enumerator _
68
+ 17 _
69
+ , _
70
+ 12 _
71
+ _
72
+ @DefaultMember _
73
+
74
+ Public Function Bar() As Variant
75
+ End Function" ;
76
+ var vbe = MockVbeBuilder . BuildFromSingleStandardModule ( inputCode , out _ ) ;
77
+ using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
78
+ {
79
+ var barDeclaration = state . DeclarationFinder . UserDeclarations ( DeclarationType . Function ) . Single ( ) ;
80
+
81
+ var expectedAnnotationCount = 3 ;
82
+ var actualAnnotationCount = barDeclaration . Annotations . Count ( ) ;
83
+
84
+ Assert . AreEqual ( expectedAnnotationCount , actualAnnotationCount ) ;
85
+ }
86
+ }
87
+
88
+ [ Test ]
89
+ public void LineContinuedAnnotationsAboveMemberGetScopedToMember_FirstMember ( )
90
+ {
91
+ const string inputCode =
92
+ @"
93
+ '@TestMethod _
94
+
95
+ '@Enumerator _
96
+ 17 _
97
+ , _
98
+ 12 _
99
+ _
100
+ @DefaultMember _
101
+
102
+ Public Sub Foo()
103
+ End Sub
104
+
105
+ Public Function Bar() As Variant
106
+ End Function" ;
107
+ var vbe = MockVbeBuilder . BuildFromSingleStandardModule ( inputCode , out _ ) ;
108
+ using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
109
+ {
110
+ var fooDeclaration = state . DeclarationFinder . UserDeclarations ( DeclarationType . Procedure ) . Single ( ) ;
111
+
112
+ var expectedAnnotationCount = 3 ;
113
+ var actualAnnotationCount = fooDeclaration . Annotations . Count ( ) ;
114
+
115
+ Assert . AreEqual ( expectedAnnotationCount , actualAnnotationCount ) ;
116
+ }
117
+ }
118
+
119
+ [ Test ]
120
+ public void AnnotationsRightAboveFirstMemberAreNotModuleAnnotations_WithDeclarationOnTop ( )
121
+ {
122
+ const string inputCode =
123
+ @"
124
+ Public Foobar As Long
125
+
126
+ '@TestMethod
127
+ '@Enumerator 17, _
128
+ 12 _
129
+ @DefaultMember
130
+ Public Sub Foo()
131
+ End Sub
132
+
133
+ Public Function Bar() As Variant
134
+ End Function" ;
135
+ var vbe = MockVbeBuilder . BuildFromSingleStandardModule ( inputCode , out _ ) ;
136
+ using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
137
+ {
138
+ var moduleDeclaration = state . DeclarationFinder . UserDeclarations ( DeclarationType . ProceduralModule ) . Single ( ) ;
139
+
140
+ var expectedAnnotationCount = 0 ;
141
+ var actualAnnotationCount = moduleDeclaration . Annotations . Count ( ) ;
142
+
143
+ Assert . AreEqual ( expectedAnnotationCount , actualAnnotationCount ) ;
144
+ }
145
+ }
146
+
147
+ [ Test ]
148
+ public void AnnotationsRightAboveFirstMemberAreNotModuleAnnotations_WithoutDeclarationOnTop ( )
149
+ {
150
+ const string inputCode =
151
+ @"
152
+ '@TestMethod
153
+ '@Enumerator 17, _
154
+ 12 _
155
+ @DefaultMember
156
+ Public Sub Foo()
157
+ End Sub
158
+
159
+ Public Function Bar() As Variant
160
+ End Function" ;
161
+ var vbe = MockVbeBuilder . BuildFromSingleStandardModule ( inputCode , out _ ) ;
162
+ using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
163
+ {
164
+ var moduleDeclaration = state . DeclarationFinder . UserDeclarations ( DeclarationType . ProceduralModule ) . Single ( ) ;
165
+
166
+ var expectedAnnotationCount = 0 ;
167
+ var actualAnnotationCount = moduleDeclaration . Annotations . Count ( ) ;
168
+
169
+ Assert . AreEqual ( expectedAnnotationCount , actualAnnotationCount ) ;
170
+ }
171
+ }
172
+
173
+ [ Test ]
174
+ public void AnnotationsAboveNonAnnotationLineAboveFirstMemberAreModuleAnnotations_WithDeclarationOnTop ( )
175
+ {
176
+ const string inputCode =
177
+ @"
178
+ Public Foobar As Long
179
+ '@TestModule
180
+ '@Folder(""Test"")
181
+ 'SomeComment
182
+ '@Enumerator 17, _
183
+ 12 _
184
+ @DefaultMember
185
+ Public Sub Foo()
186
+ End Sub
187
+
188
+ Public Function Bar() As Variant
189
+ End Function" ;
190
+ var vbe = MockVbeBuilder . BuildFromSingleStandardModule ( inputCode , out _ ) ;
191
+ using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
192
+ {
193
+ var moduleDeclaration = state . DeclarationFinder . UserDeclarations ( DeclarationType . ProceduralModule ) . Single ( ) ;
194
+
195
+ var expectedAnnotationCount = 2 ;
196
+ var actualAnnotationCount = moduleDeclaration . Annotations . Count ( ) ;
197
+
198
+ Assert . AreEqual ( expectedAnnotationCount , actualAnnotationCount ) ;
199
+ }
200
+ }
201
+
202
+ [ Test ]
203
+ public void AnnotationsAboveNonAnnotationLineAboveFirstMemberAreModuleAnnotations_WithoutDeclarationOnTop ( )
204
+ {
205
+ const string inputCode =
206
+ @"
207
+ '@TestModule
208
+ '@Folder(""Test"")
209
+ 'SomeComment
210
+ '@Enumerator 17, _
211
+ 12 _
212
+ @DefaultMember
213
+ Public Sub Foo()
214
+ End Sub
215
+
216
+ Public Function Bar() As Variant
217
+ End Function" ;
218
+ var vbe = MockVbeBuilder . BuildFromSingleStandardModule ( inputCode , out _ ) ;
219
+ using ( var state = MockParser . CreateAndParse ( vbe . Object ) )
220
+ {
221
+ var moduleDeclaration = state . DeclarationFinder . UserDeclarations ( DeclarationType . ProceduralModule ) . Single ( ) ;
222
+
223
+ var expectedAnnotationCount = 2 ;
224
+ var actualAnnotationCount = moduleDeclaration . Annotations . Count ( ) ;
225
+
226
+ Assert . AreEqual ( expectedAnnotationCount , actualAnnotationCount ) ;
227
+ }
228
+ }
229
+ }
230
+ }
0 commit comments