-
Notifications
You must be signed in to change notification settings - Fork 50
/
Copy pathEndOfCommentTest.java
366 lines (312 loc) · 12.3 KB
/
EndOfCommentTest.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
package com.sap.adt.abapcleaner.rules.syntax;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import com.sap.adt.abapcleaner.rulebase.RuleID;
import com.sap.adt.abapcleaner.rulebase.RuleTestBase;
public class EndOfCommentTest extends RuleTestBase {
private EndOfCommentRule rule;
EndOfCommentTest() {
super(RuleID.END_OF_COMMENT);
rule = (EndOfCommentRule)getRule();
}
@BeforeEach
void setUp() {
// setup default test configuration (may be modified in the individual test methods)
rule.configEndOfCommentActionInsideMethod.setEnumValue(EndOfCommentAction.REMOVE_REDUNDANT);
rule.configEndOfCommentActionOutsideMethod.setEnumValue(EndOfCommentAction.REMOVE_REDUNDANT);
rule.configLineLimitInsideMethod.setValue(50);
}
@Test
void testRemoveRedundantInsideMethod() {
buildSrc(" LOOP AT its_item INTO DATA(ls_item).");
buildSrc(" AT NEW group.");
buildSrc(" ENDAT. \" new group");
buildSrc("");
buildSrc(" IF ls_item-inner_item IS NOT INITIAL.");
buildSrc(" LOOP AT ls_item-inner_item TRANSPORTING NO FIELDS.");
buildSrc(" ENDLOOP. \" at ls_item-inner_item");
buildSrc(" ENDIF. \" ls_item-inner_item not initial.");
buildSrc("");
buildSrc(" AT END OF group.");
buildSrc(" ENDAT. \" some non-redundant comment");
buildSrc(" ENDLOOP. \" at item");
buildExp(" LOOP AT its_item INTO DATA(ls_item).");
buildExp(" AT NEW group.");
buildExp(" ENDAT.");
buildExp("");
buildExp(" IF ls_item-inner_item IS NOT INITIAL.");
buildExp(" LOOP AT ls_item-inner_item TRANSPORTING NO FIELDS.");
buildExp(" ENDLOOP.");
buildExp(" ENDIF.");
buildExp("");
buildExp(" AT END OF group.");
buildExp(" ENDAT. \" some non-redundant comment");
buildExp(" ENDLOOP.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testRemoveRedundantInsideMethodWithoutPrefixes() {
// same as previous test, but with identifiers that have no prefixes
// additionally, use component "group_" with trailing underscore
buildSrc(" LOOP AT items INTO DATA(item).");
buildSrc(" AT NEW group_.");
buildSrc(" init( item-group_ ).");
buildSrc(" ENDAT. \" new group");
buildSrc("");
buildSrc(" IF item-inner_item IS NOT INITIAL.");
buildSrc(" LOOP AT item-inner_item TRANSPORTING NO FIELDS.");
buildSrc(" \" some useful comment");
buildSrc(" ENDLOOP. \" at item-inner_item");
buildSrc(" ENDIF. \" item-inner_item not initial.");
buildSrc("");
buildSrc(" AT END OF group_.");
buildSrc(" finalize( item-group_ ).");
buildSrc(" ENDAT. \" some non-redundant comment");
buildSrc(" ENDLOOP. \" at items");
buildExp(" LOOP AT items INTO DATA(item).");
buildExp(" AT NEW group_.");
buildExp(" init( item-group_ ).");
buildExp(" ENDAT.");
buildExp("");
buildExp(" IF item-inner_item IS NOT INITIAL.");
buildExp(" LOOP AT item-inner_item TRANSPORTING NO FIELDS.");
buildExp(" \" some useful comment");
buildExp(" ENDLOOP.");
buildExp(" ENDIF.");
buildExp("");
buildExp(" AT END OF group_.");
buildExp(" finalize( item-group_ ).");
buildExp(" ENDAT. \" some non-redundant comment");
buildExp(" ENDLOOP.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testKeepAllInsideMethod() {
rule.configEndOfCommentActionInsideMethod.setEnumValue(EndOfCommentAction.KEEP);
buildSrc(" LOOP AT its_item INTO DATA(ls_item).");
buildSrc(" AT NEW group.");
buildSrc(" ENDAT. \" new group");
buildSrc("");
buildSrc(" IF ls_item-inner_item IS NOT INITIAL.");
buildSrc(" LOOP AT ls_item-inner_item TRANSPORTING NO FIELDS.");
buildSrc(" ENDLOOP. \" at ls_item-inner_item");
buildSrc(" ENDIF. \" ls_item-inner_item not initial.");
buildSrc("");
buildSrc(" AT END OF group.");
buildSrc(" ENDAT. \" some non-redundant comment");
buildSrc(" ENDLOOP. \" at item");
copyExpFromSrc();
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testRemoveAllInsideMethod() {
// expect all end-of comments to be removed, except the pseudo-comment
rule.configEndOfCommentActionInsideMethod.setEnumValue(EndOfCommentAction.REMOVE_ALL);
buildSrc(" LOOP AT its_item INTO DATA(ls_item).");
buildSrc(" AT NEW group.");
buildSrc(" ENDAT. \" new group");
buildSrc("");
buildSrc(" IF ls_item-inner_item IS NOT INITIAL.");
buildSrc(" LOOP AT ls_item-inner_item TRANSPORTING NO FIELDS.");
buildSrc(" ENDLOOP. \"#EC any_pseudo_comment");
buildSrc(" ENDIF. \" ls_item-inner_item not initial.");
buildSrc("");
buildSrc(" AT END OF group.");
buildSrc(" ENDAT. \" some non-redundant comment");
buildSrc(" ENDLOOP. \" at item");
buildExp(" LOOP AT its_item INTO DATA(ls_item).");
buildExp(" AT NEW group.");
buildExp(" ENDAT.");
buildExp("");
buildExp(" IF ls_item-inner_item IS NOT INITIAL.");
buildExp(" LOOP AT ls_item-inner_item TRANSPORTING NO FIELDS.");
buildExp(" ENDLOOP. \"#EC any_pseudo_comment");
buildExp(" ENDIF.");
buildExp("");
buildExp(" AT END OF group.");
buildExp(" ENDAT.");
buildExp(" ENDLOOP.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testRemoveRedundantOutsideMethod() {
buildSrc("CLASS lcl_any_class DEFINITION.");
buildSrc(" PUBLIC SECTION.");
buildSrc("ENDCLASS. \" any class definition");
buildSrc("");
buildSrc("CLASS lcl_any_class IMPLEMENTATION.");
buildSrc(" METHOD remove_end_of_comments.");
buildSrc(" ENDMETHOD. \" REMOVE_END_OF_COMMENTS");
buildSrc("");
buildSrc(" METHOD other_method.");
buildSrc(" ENDMETHOD. \" remove_end_of_comments (copy error)");
buildSrc("");
buildSrc(" METHOD third_method.");
buildSrc(" ENDMETHOD. \"#EC CI_NOES #EC CI_CYCLO");
buildSrc("ENDCLASS. \" lcl_any_class IMPLEMENTATION");
buildExp("CLASS lcl_any_class DEFINITION.");
buildExp(" PUBLIC SECTION.");
buildExp("ENDCLASS.");
buildExp("");
buildExp("CLASS lcl_any_class IMPLEMENTATION.");
buildExp(" METHOD remove_end_of_comments.");
buildExp(" ENDMETHOD.");
buildExp("");
buildExp(" METHOD other_method.");
buildExp(" ENDMETHOD. \" remove_end_of_comments (copy error)");
buildExp("");
buildExp(" METHOD third_method.");
buildExp(" ENDMETHOD. \"#EC CI_NOES #EC CI_CYCLO");
buildExp("ENDCLASS.");
testRule();
}
@Test
void testKeepAllOutsideMethod() {
rule.configEndOfCommentActionOutsideMethod.setEnumValue(EndOfCommentAction.KEEP);
buildSrc("CLASS lcl_any_class DEFINITION.");
buildSrc(" PUBLIC SECTION.");
buildSrc("ENDCLASS. \" any class definition");
buildSrc("");
buildSrc("");
buildSrc("CLASS lcl_any_class IMPLEMENTATION.");
buildSrc(" METHOD remove_end_of_comments.");
buildSrc(" ENDMETHOD. \" REMOVE_END_OF_COMMENTS");
buildSrc("");
buildSrc(" METHOD other_method.");
buildSrc(" ENDMETHOD. \" remove_end_of_comments (copy error)");
buildSrc("");
buildSrc(" METHOD third_method.");
buildSrc(" ENDMETHOD. \"#EC CI_NOES #EC CI_CYCLO");
buildSrc("ENDCLASS. \" lcl_any_class IMPLEMENTATION");
copyExpFromSrc();
testRule();
}
@Test
void testRemoveAllOutsideMethod() {
// expect all end-of comments to be removed, except the pseudo-comment
rule.configEndOfCommentActionOutsideMethod.setEnumValue(EndOfCommentAction.REMOVE_ALL);
buildSrc("CLASS lcl_any_class DEFINITION.");
buildSrc(" PUBLIC SECTION.");
buildSrc("ENDCLASS. \" any class definition");
buildSrc("");
buildSrc("");
buildSrc("CLASS lcl_any_class IMPLEMENTATION.");
buildSrc(" METHOD remove_end_of_comments.");
buildSrc(" ENDMETHOD. \" REMOVE_END_OF_COMMENTS");
buildSrc("");
buildSrc(" METHOD other_method.");
buildSrc(" ENDMETHOD. \" remove_end_of_comments (copy error)");
buildSrc("");
buildSrc(" METHOD third_method.");
buildSrc(" ENDMETHOD. \"#EC CI_NOES #EC CI_CYCLO");
buildSrc("ENDCLASS. \" lcl_any_class IMPLEMENTATION");
buildExp("CLASS lcl_any_class DEFINITION.");
buildExp(" PUBLIC SECTION.");
buildExp("ENDCLASS.");
buildExp("");
buildExp("");
buildExp("CLASS lcl_any_class IMPLEMENTATION.");
buildExp(" METHOD remove_end_of_comments.");
buildExp(" ENDMETHOD.");
buildExp("");
buildExp(" METHOD other_method.");
buildExp(" ENDMETHOD.");
buildExp("");
buildExp(" METHOD third_method.");
buildExp(" ENDMETHOD. \"#EC CI_NOES #EC CI_CYCLO");
buildExp("ENDCLASS.");
testRule();
}
@Test
void testKeepIfLineLimitExceeded() {
// expect the comment at the last ENDLOOP to be kept, because the opening command is > 10 lines away
rule.configLineLimitInsideMethod.setValue(10);
buildSrc(" LOOP AT its_item INTO DATA(ls_item).");
buildSrc(" AT NEW group.");
buildSrc(" init( its_item-group ).");
buildSrc(" ENDAT. \" new group");
buildSrc("");
buildSrc(" IF ls_item-inner_item IS NOT INITIAL.");
buildSrc(" LOOP AT ls_item-inner_item TRANSPORTING NO FIELDS.");
buildSrc(" \" some useful comment");
buildSrc(" ENDLOOP. \" at ls_item-inner_item");
buildSrc(" ENDIF. \" ls_item-inner_item not initial.");
buildSrc("");
buildSrc(" AT END OF group.");
buildSrc(" finalize( its_item-group ).");
buildSrc(" ENDAT. \" some non-redundant comment");
buildSrc(" ENDLOOP. \" at item");
buildExp(" LOOP AT its_item INTO DATA(ls_item).");
buildExp(" AT NEW group.");
buildExp(" init( its_item-group ).");
buildExp(" ENDAT.");
buildExp("");
buildExp(" IF ls_item-inner_item IS NOT INITIAL.");
buildExp(" LOOP AT ls_item-inner_item TRANSPORTING NO FIELDS.");
buildExp(" \" some useful comment");
buildExp(" ENDLOOP.");
buildExp(" ENDIF.");
buildExp("");
buildExp(" AT END OF group.");
buildExp(" finalize( its_item-group ).");
buildExp(" ENDAT. \" some non-redundant comment");
buildExp(" ENDLOOP. \" at item");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testRemoveCompleteMatch() {
buildSrc(" LOOP AT its_item INTO DATA(ls_item).");
buildSrc(" IF ls_item-inner_item IS NOT INITIAL.");
buildSrc(" LOOP AT ls_item-inner_item TRANSPORTING NO FIELDS.");
buildSrc(" ENDLOOP. \" AT ls_item-inner_item TRANSPORTING NO FIELDS.");
buildSrc(" ENDIF. \" ls_item-inner_item IS NOT INITIAL.");
buildSrc(" ENDLOOP. \" LOOP AT its_item INTO DATA(ls_item).");
buildExp(" LOOP AT its_item INTO DATA(ls_item).");
buildExp(" IF ls_item-inner_item IS NOT INITIAL.");
buildExp(" LOOP AT ls_item-inner_item TRANSPORTING NO FIELDS.");
buildExp(" ENDLOOP.");
buildExp(" ENDIF.");
buildExp(" ENDLOOP.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testIfWithBrackets() {
// expect the end-of comment to be removed even though it does not have the parentheses
buildSrc(" IF ( a = b ) OR ( b = c ).");
buildSrc(" ENDIF. \" a = b OR b = c");
buildExp(" IF ( a = b ) OR ( b = c ).");
buildExp(" ENDIF.");
testRule();
putAnyMethodAroundSrcAndExp();
}
@Test
void testPragmaAndCommentSkipped() {
// expect the end-of comment ot be removed even though it does not contain the pragma and comment
buildSrc(" LOOP AT its_table INTO DATA(ls_line) ##NEEDED \" comment");
buildSrc(" WHERE id > 10.");
buildSrc(" ENDLOOP. \" AT its_table INTO DATA(ls_line) WHERE id > 10.");
buildExp(" LOOP AT its_table INTO DATA(ls_line) ##NEEDED \" comment");
buildExp(" WHERE id > 10.");
buildExp(" ENDLOOP.");
testRule();
}
@Test
void testIncompleteIdentifierKept() {
// expect the second end-of comment to be kept, because it does not contain the complete identifier
buildSrc(" IF lv_very_long_variable_name = 1.");
buildSrc(" ENDIF. \" very long variable name = 1");
buildSrc(" IF lv_very_long_variable_name = 1.");
buildSrc(" ENDIF. \" very long variable = 1");
buildExp(" IF lv_very_long_variable_name = 1.");
buildExp(" ENDIF.");
buildExp(" IF lv_very_long_variable_name = 1.");
buildExp(" ENDIF. \" very long variable = 1");
testRule();
}
}