-
Notifications
You must be signed in to change notification settings - Fork 53
/
Copy pathAlignDeclarationsTest.java
1827 lines (1497 loc) · 69.5 KB
/
AlignDeclarationsTest.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
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
package com.sap.adt.abapcleaner.rules.alignment;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import com.sap.adt.abapcleaner.rulebase.RuleID;
import com.sap.adt.abapcleaner.rulebase.RuleTestBase;
class AlignDeclarationsTest extends RuleTestBase {
private AlignDeclarationsRule rule;
AlignDeclarationsTest() {
super(RuleID.ALIGN_DECLARATIONS);
rule = (AlignDeclarationsRule)getRule();
}
@BeforeEach
void setUp() {
// setup default test configuration (may be modified in the individual test methods)
rule.configExecuteOnClassDefAndInterfaces.setValue(true);
rule.configAlignChainAction.setEnumValue(AlignDeclarationsAction.ALIGN_NAME_TYPE_LENGTH_ETC);
rule.configAlignNonChainsAction.setEnumValue(AlignDeclarationsAction.ALIGN_NAME_TYPE_LENGTH_ETC);
rule.configAlignAcrossEmptyLines.setValue(true);
rule.configAlignAcrossCommentLines.setValue(true);
rule.configAlignStructureAction.setEnumValue(AlignDeclarationsAction.ALIGN_NAME_TYPE_LENGTH_ETC);
rule.configStructureAlignStyle.setEnumValue(StructureAlignStyle.PER_LEVEL);
rule.configFillPercentageToJustifyOwnColumn.setValue(20);
rule.configCondenseInnerSpaces.setValue(true);
}
@Test
void testConstantsChain() {
buildSrc(" CONSTANTS: lc_item_list_price_1200 TYPE ty_list_price VALUE 1200,");
buildSrc(" lc_item_amount_1000 TYPE ty_amount VALUE 1000,");
buildSrc(" lc_num_process TYPE ty_sequence_number VALUE 1,");
buildSrc(" lc_final_date TYPE ty_date VALUE '20201012'.");
buildExp(" CONSTANTS: lc_item_list_price_1200 TYPE ty_list_price VALUE 1200,");
buildExp(" lc_item_amount_1000 TYPE ty_amount VALUE 1000,");
buildExp(" lc_num_process TYPE ty_sequence_number VALUE 1,");
buildExp(" lc_final_date TYPE ty_date VALUE '20201012'.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testConstantsBlock() {
buildSrc(" \" the rule aligns subsequent declaration lines just like chains");
buildSrc(" CONSTANTS lc_item_name_smartphone TYPE ty_item_name VALUE 'SMARTPHONE' ##NO_TEXT.");
buildSrc(" CONSTANTS lc_item_name_subscription TYPE ty_item_name VALUE 'SUBSCRIPTION' ##NO_TEXT.");
buildSrc(" CONSTANTS lc_item_name_service TYPE ty_item_name VALUE 'SERVICE' ##NO_TEXT.");
buildExp(" \" the rule aligns subsequent declaration lines just like chains");
buildExp(" CONSTANTS lc_item_name_smartphone TYPE ty_item_name VALUE 'SMARTPHONE' ##NO_TEXT.");
buildExp(" CONSTANTS lc_item_name_subscription TYPE ty_item_name VALUE 'SUBSCRIPTION' ##NO_TEXT.");
buildExp(" CONSTANTS lc_item_name_service TYPE ty_item_name VALUE 'SERVICE' ##NO_TEXT.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testDataChain() {
buildSrc(" DATA: ls_any_item TYPE ty_item,");
buildSrc(" lo_any_contract TYPE REF TO ty_contract,");
buildSrc(" ls_change TYPE ty_change,");
buildSrc(" lt_table TYPE ty_ts_table.");
buildExp(" DATA: ls_any_item TYPE ty_item,");
buildExp(" lo_any_contract TYPE REF TO ty_contract,");
buildExp(" ls_change TYPE ty_change,");
buildExp(" lt_table TYPE ty_ts_table.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testDataBlockWithNoCommentAlign() {
buildSrc(" \" if only a single declaration (or a very small ratio of them) has a VALUE, a comment, etc.,");
buildSrc(" \" no extra column is created for it");
buildSrc(" DATA lth_any_table TYPE ty_th_table. \" only line with a comment");
buildSrc(" DATA lo_contract TYPE REF TO cl_contract ##NEEDED.");
buildSrc(" DATA ls_any_struc TYPE if_contract=>ty_s_struc.");
buildSrc(" DATA mv_any_bool_value TYPE abap_bool VALUE abap_false ##NO_TEXT.");
buildExp(" \" if only a single declaration (or a very small ratio of them) has a VALUE, a comment, etc.,");
buildExp(" \" no extra column is created for it");
buildExp(" DATA lth_any_table TYPE ty_th_table. \" only line with a comment");
buildExp(" DATA lo_contract TYPE REF TO cl_contract ##NEEDED.");
buildExp(" DATA ls_any_struc TYPE if_contract=>ty_s_struc.");
buildExp(" DATA mv_any_bool_value TYPE abap_bool VALUE abap_false ##NO_TEXT.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testFieldSymbolsChainWithCommentAlign() {
buildSrc(" FIELD-SYMBOLS:");
buildSrc(" <fs_item_data> TYPE ty_s_item_data, \" first comment line");
buildSrc(" <lfs_invoice_amt> LIKE LINE OF its_invoice,");
buildSrc(" <ls_contract_data> TYPE ty_s_contract, \" second comment line");
buildSrc(" <ls_param> LIKE LINE OF mt_parameter.");
buildExp(" FIELD-SYMBOLS:");
buildExp(" <fs_item_data> TYPE ty_s_item_data, \" first comment line");
buildExp(" <lfs_invoice_amt> LIKE LINE OF its_invoice,");
buildExp(" <ls_contract_data> TYPE ty_s_contract, \" second comment line");
buildExp(" <ls_param> LIKE LINE OF mt_parameter.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testFieldSymbolsChainWithNoCommentAlign() {
rule.configFillPercentageToJustifyOwnColumn.setValue(75);
buildSrc(" FIELD-SYMBOLS:");
buildSrc(" <fs_item_data> TYPE ty_s_item_data, \" first comment line");
buildSrc(" <lfs_invoice_amt> LIKE LINE OF its_invoice,");
buildSrc(" <ls_contract_data> TYPE ty_s_contract, \" second comment line");
buildSrc(" <ls_param> LIKE LINE OF mt_parameter.");
buildExp(" FIELD-SYMBOLS:");
buildExp(" <fs_item_data> TYPE ty_s_item_data, \" first comment line");
buildExp(" <lfs_invoice_amt> LIKE LINE OF its_invoice,");
buildExp(" <ls_contract_data> TYPE ty_s_contract, \" second comment line");
buildExp(" <ls_param> LIKE LINE OF mt_parameter.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testFieldSymbolsBlock() {
buildSrc(" FIELD-SYMBOLS <fs_item_data> TYPE ty_s_item_data.");
buildSrc(" FIELD-SYMBOLS <lfs_invoice_amt> LIKE LINE OF its_invoice.");
buildSrc(" FIELD-SYMBOLS <ls_contract_data> TYPE ty_s_contract.");
buildExp(" FIELD-SYMBOLS <fs_item_data> TYPE ty_s_item_data.");
buildExp(" FIELD-SYMBOLS <lfs_invoice_amt> LIKE LINE OF its_invoice.");
buildExp(" FIELD-SYMBOLS <ls_contract_data> TYPE ty_s_contract.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testAlignAcrossCommentsAndEmptyLines() {
rule.configAlignAcrossCommentLines.setValue(true);
rule.configAlignAcrossEmptyLines.setValue(true);
buildSrc(" \" alignment across comments and empty lines (depending on configuration):");
buildSrc(" DATA lv_value TYPE i.");
buildSrc(" \" comment");
buildSrc(" DATA lv_long_variable_name TYPE string.");
buildSrc("");
buildSrc(" DATA lts_sorted_table LIKE its_table.");
buildExp(" \" alignment across comments and empty lines (depending on configuration):");
buildExp(" DATA lv_value TYPE i.");
buildExp(" \" comment");
buildExp(" DATA lv_long_variable_name TYPE string.");
buildExp("");
buildExp(" DATA lts_sorted_table LIKE its_table.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testDontAlignAcrossCommentsAndEmptyLines() {
rule.configAlignAcrossCommentLines.setValue(false);
rule.configAlignAcrossEmptyLines.setValue(false);
buildSrc(" \" no alignment across comments and empty lines (depending on configuration):");
buildSrc(" DATA lv_value TYPE i.");
buildSrc(" DATA lv_value_2 TYPE i.");
buildSrc(" \" comment");
buildSrc(" DATA lv_long_variable_name TYPE string.");
buildSrc(" DATA lv_long_variable_name_2 TYPE string.");
buildSrc("");
buildSrc(" DATA lts_sorted_table LIKE its_table.");
buildSrc(" DATA lts_sorted_table_2 LIKE its_table.");
buildExp(" \" no alignment across comments and empty lines (depending on configuration):");
buildExp(" DATA lv_value TYPE i.");
buildExp(" DATA lv_value_2 TYPE i.");
buildExp(" \" comment");
buildExp(" DATA lv_long_variable_name TYPE string.");
buildExp(" DATA lv_long_variable_name_2 TYPE string.");
buildExp("");
buildExp(" DATA lts_sorted_table LIKE its_table.");
buildExp(" DATA lts_sorted_table_2 LIKE its_table.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testIdentifierWithLengthInParens() {
buildSrc(" \" identifiers with length information in parentheses:");
buildSrc(" DATA: lv_textdat1(20) TYPE c,");
buildSrc(" lv_textdat2(20) TYPE c.");
buildExp(" \" identifiers with length information in parentheses:");
buildExp(" DATA: lv_textdat1(20) TYPE c,");
buildExp(" lv_textdat2(20) TYPE c.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testTypesBeginOf() {
buildSrc(" TYPES: BEGIN of xyz,");
buildSrc(" a TYPE x,");
buildSrc(" b TYPE y,");
buildSrc(" c TYPE z,");
buildSrc(" END OF xyz.");
buildExp(" TYPES: BEGIN of xyz,");
buildExp(" a TYPE x,");
buildExp(" b TYPE y,");
buildExp(" c TYPE z,");
buildExp(" END OF xyz.");
putAnyClassDefAroundSrcAndExp();
testRule();
}
@Test
void testTypesBeginOfWithComments() {
buildSrc(" TYPES: BEGIN of xyz,");
buildSrc(" a TYPE x, \" comment");
buildSrc(" b TYPE y,");
buildSrc(" c TYPE z, \" comment");
buildSrc(" END OF xyz.");
buildExp(" TYPES: BEGIN of xyz,");
buildExp(" a TYPE x, \" comment");
buildExp(" b TYPE y,");
buildExp(" c TYPE z, \" comment");
buildExp(" END OF xyz.");
putAnyClassDefAroundSrcAndExp();
testRule();
}
@Test
void testTypesBeginOfTypesEndOf() {
// test an extra TYPES without chain colon directly before END OF
buildSrc(" TYPES: BEGIN OF ty_s_struc,");
buildSrc(" comp TYPE i.");
buildSrc(" TYPES END OF ty_s_struc.");
buildExp(" TYPES: BEGIN OF ty_s_struc,");
buildExp(" comp TYPE i.");
buildExp(" TYPES END OF ty_s_struc.");
putAnyClassDefAroundSrcAndExp();
testRule();
}
@Test
void testTypesBeginOfIncludeTypesEndOf() {
// test an INCLUDE, directly followed by TYPES END OF (without chain colon)
buildSrc(" TYPES: BEGIN OF ty_s_struc,");
buildSrc(" comp TYPE i.");
buildSrc(" INCLUDE TYPE ty_s_include.");
buildSrc(" TYPES END OF ty_s_struc.");
buildExp(" TYPES: BEGIN OF ty_s_struc,");
buildExp(" comp TYPE i.");
buildExp(" INCLUDE TYPE ty_s_include.");
buildExp(" TYPES END OF ty_s_struc.");
putAnyClassDefAroundSrcAndExp();
testRule();
}
@Test
void testTypesBeginOfBetweenOtherTypes() {
// ensure that independent TYPES before and after the structure are aligned separately
buildSrc(" TYPES ty_any TYPE string.");
buildSrc(" TYPES ty_other TYPE string.");
buildSrc(" TYPES: BEGIN OF ty_s_struc,");
buildSrc(" comp TYPE i.");
buildSrc(" INCLUDE TYPE ty_s_include.");
buildSrc(" TYPES: END OF ty_s_struc.");
buildSrc(" TYPES ty_any_long TYPE string.");
buildSrc(" TYPES ty_other_long TYPE string.");
buildExp(" TYPES ty_any TYPE string.");
buildExp(" TYPES ty_other TYPE string.");
buildExp(" TYPES: BEGIN OF ty_s_struc,");
buildExp(" comp TYPE i.");
buildExp(" INCLUDE TYPE ty_s_include.");
buildExp(" TYPES: END OF ty_s_struc.");
buildExp(" TYPES ty_any_long TYPE string.");
buildExp(" TYPES ty_other_long TYPE string.");
putAnyClassDefAroundSrcAndExp();
testRule();
}
@Test
void testBeginOfWithInclude() {
buildSrc(" TYPES:");
buildSrc(" BEGIN OF ty_s_any_struc,");
buildSrc(" component_a TYPE i,");
buildSrc(" component_b_long TYPE i.");
buildSrc(" INCLUDE TYPE ty_s_include.");
buildSrc(" TYPES:");
buildSrc(" component_c TYPE i,");
buildSrc(" END OF ty_s_any_struc.");
buildSrc("");
buildSrc(" DATA mv_any TYPE i.");
buildExp(" TYPES:");
buildExp(" BEGIN OF ty_s_any_struc,");
buildExp(" component_a TYPE i,");
buildExp(" component_b_long TYPE i.");
buildExp(" INCLUDE TYPE ty_s_include.");
buildExp(" TYPES:");
buildExp(" component_c TYPE i,");
buildExp(" END OF ty_s_any_struc.");
buildExp("");
buildExp(" DATA mv_any TYPE i.");
putAnyClassDefAroundSrcAndExp();
testRule();
}
@Test
void testBeginOfWithIncludeAndComment() {
// ensure that the comment after the INCLUDE TYPE line does not affect the alignment of the components' TYPE column
buildSrc(" TYPES: BEGIN OF ty_s_any_struc,");
buildSrc(" component_a TYPE i,");
buildSrc(" comp_b TYPE string.");
buildSrc(" INCLUDE TYPE ty_s_include. \" comment");
buildSrc(" TYPES: END OF ty_s_any_struc.");
buildExp(" TYPES: BEGIN OF ty_s_any_struc,");
buildExp(" component_a TYPE i,");
buildExp(" comp_b TYPE string.");
buildExp(" INCLUDE TYPE ty_s_include. \" comment");
buildExp(" TYPES: END OF ty_s_any_struc.");
putAnyClassDefAroundSrcAndExp();
testRule();
}
@Test
void testBeginOfWithIncludeAndCommentLines() {
buildSrc(" TYPES:");
buildSrc(" \" comment");
buildSrc(" BEGIN OF ty_s_any_struc,");
buildSrc(" component_a TYPE i,");
buildSrc(" component_b_long TYPE i.");
buildSrc(" \" comment");
buildSrc(" INCLUDE TYPE ty_s_include.");
buildSrc(" TYPES:");
buildSrc(" \" comment");
buildSrc(" component_c TYPE i,");
buildSrc(" \" comment");
buildSrc(" END OF ty_s_any_struc.");
buildSrc("");
buildSrc(" DATA mv_any TYPE i.");
buildExp(" TYPES:");
buildExp(" \" comment");
buildExp(" BEGIN OF ty_s_any_struc,");
buildExp(" component_a TYPE i,");
buildExp(" component_b_long TYPE i.");
buildExp(" \" comment");
buildExp(" INCLUDE TYPE ty_s_include.");
buildExp(" TYPES:");
buildExp(" \" comment");
buildExp(" component_c TYPE i,");
buildExp(" \" comment");
buildExp(" END OF ty_s_any_struc.");
buildExp("");
buildExp(" DATA mv_any TYPE i.");
putAnyClassDefAroundSrcAndExp();
testRule();
}
@Test
void testNestedBeginOf() {
buildSrc(" TYPES:");
buildSrc(" BEGIN OF ty_s_any_struc,");
buildSrc(" component_a TYPE i,");
buildSrc(" BEGIN OF ty_s_inner,");
buildSrc(" comp_1_long TYPE i,");
buildSrc(" comp_2 TYPE i,");
buildSrc(" END OF ty_s_inner,");
buildSrc(" component_b_long TYPE i,");
buildSrc(" component_c TYPE i,");
buildSrc(" END OF ty_s_any_struc.");
buildSrc("");
buildSrc(" DATA mv_any TYPE i.");
buildExp(" TYPES:");
buildExp(" BEGIN OF ty_s_any_struc,");
buildExp(" component_a TYPE i,");
buildExp(" BEGIN OF ty_s_inner,");
buildExp(" comp_1_long TYPE i,");
buildExp(" comp_2 TYPE i,");
buildExp(" END OF ty_s_inner,");
buildExp(" component_b_long TYPE i,");
buildExp(" component_c TYPE i,");
buildExp(" END OF ty_s_any_struc.");
buildExp("");
buildExp(" DATA mv_any TYPE i.");
putAnyClassDefAroundSrcAndExp();
testRule();
}
@Test
void testNestedBeginOfWithComments() {
buildSrc(" TYPES:");
buildSrc(" \" comment");
buildSrc(" BEGIN OF ty_s_any_struc,");
buildSrc(" \" comment");
buildSrc(" component_a TYPE i,");
buildSrc(" BEGIN OF ty_s_inner,");
buildSrc(" comp_1_long TYPE i,");
buildSrc(" \" comment");
buildSrc(" comp_2 TYPE i,");
buildSrc(" END OF ty_s_inner,");
buildSrc(" component_b_long TYPE i,");
buildSrc(" component_c TYPE i,");
buildSrc(" \" comment");
buildSrc(" END OF ty_s_any_struc.");
buildSrc("");
buildSrc(" DATA mv_any TYPE i.");
buildExp(" TYPES:");
buildExp(" \" comment");
buildExp(" BEGIN OF ty_s_any_struc,");
buildExp(" \" comment");
buildExp(" component_a TYPE i,");
buildExp(" BEGIN OF ty_s_inner,");
buildExp(" comp_1_long TYPE i,");
buildExp(" \" comment");
buildExp(" comp_2 TYPE i,");
buildExp(" END OF ty_s_inner,");
buildExp(" component_b_long TYPE i,");
buildExp(" component_c TYPE i,");
buildExp(" \" comment");
buildExp(" END OF ty_s_any_struc.");
buildExp("");
buildExp(" DATA mv_any TYPE i.");
putAnyClassDefAroundSrcAndExp();
testRule();
}
@Test
void testNestedBeginOfBehindKeyword() {
buildSrc(" TYPES: BEGIN OF ty_s_any_struc,");
buildSrc(" component_a TYPE i,");
buildSrc(" BEGIN OF ty_s_inner,");
buildSrc(" comp_1_long TYPE i,");
buildSrc(" comp_2 TYPE i,");
buildSrc(" END OF ty_s_inner,");
buildSrc(" component_b_long TYPE i,");
buildSrc(" component_c TYPE i,");
buildSrc(" END OF ty_s_any_struc.");
buildSrc("");
buildSrc(" DATA mv_any TYPE i.");
buildExp(" TYPES: BEGIN OF ty_s_any_struc,");
buildExp(" component_a TYPE i,");
buildExp(" BEGIN OF ty_s_inner,");
buildExp(" comp_1_long TYPE i,");
buildExp(" comp_2 TYPE i,");
buildExp(" END OF ty_s_inner,");
buildExp(" component_b_long TYPE i,");
buildExp(" component_c TYPE i,");
buildExp(" END OF ty_s_any_struc.");
buildExp("");
buildExp(" DATA mv_any TYPE i.");
putAnyClassDefAroundSrcAndExp();
testRule();
}
@Test
void testNestedBeginOfBehindKeywordWithComments() {
buildSrc(" TYPES: BEGIN OF ty_s_any_struc,");
buildSrc(" component_a TYPE i, \" comment A");
buildSrc(" BEGIN OF ty_s_inner,");
buildSrc(" comp_1_long TYPE i,");
buildSrc(" comp_2 TYPE i, \" comment 2");
buildSrc(" END OF ty_s_inner,");
buildSrc(" component_b_long TYPE i, \" comment B");
buildSrc(" component_c TYPE i,");
buildSrc(" END OF ty_s_any_struc.");
buildSrc("");
buildSrc(" DATA mv_any TYPE i.");
buildExp(" TYPES: BEGIN OF ty_s_any_struc,");
buildExp(" component_a TYPE i, \" comment A");
buildExp(" BEGIN OF ty_s_inner,");
buildExp(" comp_1_long TYPE i,");
buildExp(" comp_2 TYPE i, \" comment 2");
buildExp(" END OF ty_s_inner,");
buildExp(" component_b_long TYPE i, \" comment B");
buildExp(" component_c TYPE i,");
buildExp(" END OF ty_s_any_struc.");
buildExp("");
buildExp(" DATA mv_any TYPE i.");
putAnyClassDefAroundSrcAndExp();
testRule();
}
@Test
void testNestedBeginOfWithInclude() {
buildSrc(" TYPES:");
buildSrc(" BEGIN OF ty_s_any_struc,");
buildSrc(" component_a TYPE i,");
buildSrc(" BEGIN OF ty_s_inner,");
buildSrc(" comp_1_long TYPE i,");
buildSrc(" comp_2 TYPE i,");
buildSrc(" END OF ty_s_inner,");
buildSrc(" component_b_long TYPE i.");
buildSrc(" INCLUDE TYPE ty_s_include.");
buildSrc(" TYPES:");
buildSrc(" component_c_long TYPE i,");
buildSrc(" component_d TYPE i,");
buildSrc(" END OF ty_s_any_struc.");
buildSrc("");
buildSrc(" DATA mv_any TYPE i.");
buildExp(" TYPES:");
buildExp(" BEGIN OF ty_s_any_struc,");
buildExp(" component_a TYPE i,");
buildExp(" BEGIN OF ty_s_inner,");
buildExp(" comp_1_long TYPE i,");
buildExp(" comp_2 TYPE i,");
buildExp(" END OF ty_s_inner,");
buildExp(" component_b_long TYPE i.");
buildExp(" INCLUDE TYPE ty_s_include.");
buildExp(" TYPES:");
buildExp(" component_c_long TYPE i,");
buildExp(" component_d TYPE i,");
buildExp(" END OF ty_s_any_struc.");
buildExp("");
buildExp(" DATA mv_any TYPE i.");
putAnyClassDefAroundSrcAndExp();
testRule();
}
@Test
void testDataBeginOf() {
// example taken from https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abennested_structure_abexa.htm
buildSrc(" DATA:");
buildSrc(" BEGIN OF address,");
buildSrc(" BEGIN OF name,");
buildSrc(" title TYPE string VALUE `Mr.`,");
buildSrc(" prename TYPE string VALUE `Duncan`,");
buildSrc(" surname TYPE string VALUE `Pea`,");
buildSrc(" END OF name,");
buildSrc(" BEGIN OF street,");
buildSrc(" name TYPE string VALUE `Vegetable Lane`,");
buildSrc(" number TYPE string VALUE `11`,");
buildSrc(" END OF street,");
buildSrc(" BEGIN OF city,");
buildSrc(" zipcode TYPE string VALUE `349875`,");
buildSrc(" name TYPE string VALUE `Botanica`,");
buildSrc(" END OF city,");
buildSrc(" END OF address.");
buildExp(" DATA:");
buildExp(" BEGIN OF address,");
buildExp(" BEGIN OF name,");
buildExp(" title TYPE string VALUE `Mr.`,");
buildExp(" prename TYPE string VALUE `Duncan`,");
buildExp(" surname TYPE string VALUE `Pea`,");
buildExp(" END OF name,");
buildExp(" BEGIN OF street,");
buildExp(" name TYPE string VALUE `Vegetable Lane`,");
buildExp(" number TYPE string VALUE `11`,");
buildExp(" END OF street,");
buildExp(" BEGIN OF city,");
buildExp(" zipcode TYPE string VALUE `349875`,");
buildExp(" name TYPE string VALUE `Botanica`,");
buildExp(" END OF city,");
buildExp(" END OF address.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testDataBeginOfNested() {
// example taken from https://help.sap.com/doc/abapdocu_latest_index_htm/latest/en-US/index.htm?file=abennested_structure_abexa.htm
buildSrc(" DATA:");
buildSrc(" BEGIN OF address,");
buildSrc(" BEGIN OF name,");
buildSrc(" title TYPE string VALUE `Mr.`,");
buildSrc(" prename TYPE string VALUE `Duncan`,");
buildSrc(" surname TYPE string VALUE `Pea`,");
buildSrc(" END OF name,");
buildSrc(" BEGIN OF street,");
buildSrc(" name TYPE string VALUE `Vegetable Lane`,");
buildSrc(" number TYPE string VALUE `11`,");
buildSrc(" END OF street,");
buildSrc(" BEGIN OF city,");
buildSrc(" zipcode TYPE string VALUE `349875`,");
buildSrc(" name TYPE string VALUE `Botanica`,");
buildSrc(" END OF city,");
buildSrc(" END OF address.");
buildExp(" DATA:");
buildExp(" BEGIN OF address,");
buildExp(" BEGIN OF name,");
buildExp(" title TYPE string VALUE `Mr.`,");
buildExp(" prename TYPE string VALUE `Duncan`,");
buildExp(" surname TYPE string VALUE `Pea`,");
buildExp(" END OF name,");
buildExp(" BEGIN OF street,");
buildExp(" name TYPE string VALUE `Vegetable Lane`,");
buildExp(" number TYPE string VALUE `11`,");
buildExp(" END OF street,");
buildExp(" BEGIN OF city,");
buildExp(" zipcode TYPE string VALUE `349875`,");
buildExp(" name TYPE string VALUE `Botanica`,");
buildExp(" END OF city,");
buildExp(" END OF address.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testTableDeclarationWithKeyOf3Components() {
// ensure that in table declarations with more than one component in the "WITH" section,
// the "WITH ..." part is kept unchanged, but everything else is aligned
buildSrc(" DATA:");
buildSrc(" lt_item TYPE ty_tt_item,");
buildSrc(" lts_buffer TYPE SORTED TABLE OF ty_s_buffer");
buildSrc(" WITH NON-UNIQUE KEY comp1 comp2 comp3,");
buildSrc(" lv_index TYPE i.");
buildExp(" DATA:");
buildExp(" lt_item TYPE ty_tt_item,");
buildExp(" lts_buffer TYPE SORTED TABLE OF ty_s_buffer");
buildExp(" WITH NON-UNIQUE KEY comp1 comp2 comp3,");
buildExp(" lv_index TYPE i.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testTableDeclarationWithMultiKey() {
// ensure that in table declarations with multiple "WITH ... KEY ..." sections, the "WITH ..." part is kept unchanged,
// but everything else is aligned
buildSrc(" DATA:");
buildSrc(" lt_item TYPE ty_tt_item,");
buildSrc(" lts_buffer TYPE SORTED TABLE OF ty_s_buffer");
buildSrc(" WITH NON-UNIQUE KEY comp1 comp2 comp3");
buildSrc(" WITH UNIQUE KEY key_name COMPONENTS comp1 comp2");
buildSrc(" comp3 comp4,");
buildSrc(" lv_index TYPE i.");
buildExp(" DATA:");
buildExp(" lt_item TYPE ty_tt_item,");
buildExp(" lts_buffer TYPE SORTED TABLE OF ty_s_buffer");
buildExp(" WITH NON-UNIQUE KEY comp1 comp2 comp3");
buildExp(" WITH UNIQUE KEY key_name COMPONENTS comp1 comp2");
buildExp(" comp3 comp4,");
buildExp(" lv_index TYPE i.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testChainSignAttachedToVarName() {
buildSrc(" \" consider that there may be no space after the : colon:");
buildSrc(" CONSTANTS:lc_any TYPE if_any_interface=>ty_any_type VALUE '101',");
buildSrc(" lc_other TYPE ty_any_quantity VALUE '%' ##NO_TEXT.");
buildSrc("");
buildSrc(" DATA:lv_msgv_item_id TYPE sy-msgv1,");
buildSrc(" lv_long_variable_name TYPE sy-tabix VALUE 1.");
buildSrc("");
buildSrc(" FIELD-SYMBOLS:<ls_any> TYPE ty_s_any,");
buildSrc(" <ls_other> TYPE ty_s_other.");
buildExp(" \" consider that there may be no space after the : colon:");
buildExp(" CONSTANTS: lc_any TYPE if_any_interface=>ty_any_type VALUE '101',");
buildExp(" lc_other TYPE ty_any_quantity VALUE '%' ##NO_TEXT.");
buildExp("");
buildExp(" DATA: lv_msgv_item_id TYPE sy-msgv1,");
buildExp(" lv_long_variable_name TYPE sy-tabix VALUE 1.");
buildExp("");
buildExp(" FIELD-SYMBOLS: <ls_any> TYPE ty_s_any,");
buildExp(" <ls_other> TYPE ty_s_other.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testAlignClassDefinition() {
rule.configExecuteOnClassDefAndInterfaces.setValue(true);
buildSrc(" CONSTANTS lc_item_name_smartphone TYPE ty_item_name VALUE 'SMARTPHONE' ##NO_TEXT.");
buildSrc(" CONSTANTS lc_item_name_subscription TYPE ty_item_name VALUE 'SUBSCRIPTION' ##NO_TEXT.");
buildSrc(" CONSTANTS lc_item_name_service TYPE ty_item_name VALUE 'SERVICE' ##NO_TEXT.");
buildExp(" CONSTANTS lc_item_name_smartphone TYPE ty_item_name VALUE 'SMARTPHONE' ##NO_TEXT.");
buildExp(" CONSTANTS lc_item_name_subscription TYPE ty_item_name VALUE 'SUBSCRIPTION' ##NO_TEXT.");
buildExp(" CONSTANTS lc_item_name_service TYPE ty_item_name VALUE 'SERVICE' ##NO_TEXT.");
putAnyClassDefAroundSrcAndExp();
testRule();
}
@Test
void testDontAlignClassDefinition() {
rule.configExecuteOnClassDefAndInterfaces.setValue(false);
buildSrc(" CONSTANTS lc_item_name_smartphone TYPE ty_item_name VALUE 'SMARTPHONE' ##NO_TEXT.");
buildSrc(" CONSTANTS lc_item_name_subscription TYPE ty_item_name VALUE 'SUBSCRIPTION' ##NO_TEXT.");
buildSrc(" CONSTANTS lc_item_name_service TYPE ty_item_name VALUE 'SERVICE' ##NO_TEXT.");
copyExpFromSrc();
putAnyClassDefAroundSrcAndExp();
testRule();
}
@Test
void testDataWithLengthDecimalsReadOnly() {
buildSrc(" DATA price TYPE p LENGTH 8 DECIMALS 2 VALUE '1.99' READ-ONLY.");
buildSrc(" DATA duration TYPE p LENGTH 5 DECIMALS 1 VALUE '57.3' READ-ONLY.");
buildSrc(" DATA info TYPE c LENGTH 250 VALUE 'text' READ-ONLY.");
buildSrc(" DATA tag TYPE p LENGTH 12 DECIMALS 10 VALUE '8.012345789' READ-ONLY.");
buildExp(" DATA price TYPE p LENGTH 8 DECIMALS 2 VALUE '1.99' READ-ONLY.");
buildExp(" DATA duration TYPE p LENGTH 5 DECIMALS 1 VALUE '57.3' READ-ONLY.");
buildExp(" DATA info TYPE c LENGTH 250 VALUE 'text' READ-ONLY.");
buildExp(" DATA tag TYPE p LENGTH 12 DECIMALS 10 VALUE '8.012345789' READ-ONLY.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testDataWithDefaultType() {
// ensure that alignment works across a declaration that uses the default type c
buildSrc(" DATA lv_offset TYPE i.");
buildSrc(" DATA lv_text(100).");
buildSrc(" DATA lv_substring TYPE string.");
buildExp(" DATA lv_offset TYPE i.");
buildExp(" DATA lv_text(100).");
buildExp(" DATA lv_substring TYPE string.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testDataChainWithDefaultType() {
// ensure that alignment works across a declaration that uses the default type c
buildSrc(" DATA: lv_offset TYPE i,");
buildSrc(" lv_text(100),");
buildSrc(" lv_substring TYPE string.");
buildExp(" DATA: lv_offset TYPE i,");
buildExp(" lv_text(100),");
buildExp(" lv_substring TYPE string.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testTypesWithSpecialCompNames() {
// ensure that component names which could be mistaken for a keyword (such as 'data' and 'types') are aligned correctly
buildSrc(" TYPES: BEGIN OF ty_structure,");
buildSrc(" component TYPE i,");
buildSrc(" data TYPE i,");
buildSrc(" types TYPE i,");
buildSrc(" methods TYPE i,");
buildSrc(" END OF ty_structure.");
buildExp(" TYPES: BEGIN OF ty_structure,");
buildExp(" component TYPE i,");
buildExp(" data TYPE i,");
buildExp(" types TYPE i,");
buildExp(" methods TYPE i,");
buildExp(" END OF ty_structure.");
putAnyMethodAroundSrcAndExp();
testRule();
}
@Test
void testTableWithShortKeyDefiniton() {
buildSrc(" METHOD any_method.");
buildSrc(" DATA lv_any_num TYPE i.");
buildSrc(" DATA lt_any_table TYPE STANDARD TABLE OF any_data_element WITH NON-UNIQUE DEFAULT KEY.");
buildSrc(" DATA lt_other_table TYPE STANDARD TABLE OF any_data_element WITH EMPTY KEY.");
buildSrc(" DATA lv_other_value TYPE string.");
buildSrc(" ENDMETHOD.");
buildExp(" METHOD any_method.");
buildExp(" DATA lv_any_num TYPE i.");
buildExp(" DATA lt_any_table TYPE STANDARD TABLE OF any_data_element WITH NON-UNIQUE DEFAULT KEY.");
buildExp(" DATA lt_other_table TYPE STANDARD TABLE OF any_data_element WITH EMPTY KEY.");
buildExp(" DATA lv_other_value TYPE string.");
buildExp(" ENDMETHOD.");
testRule();
}
@Test
void testTypesColonIncludeTypes() {
buildSrc(" TYPES:");
buildSrc(" BEGIN OF ty_s_any_struc.");
buildSrc(" INCLUDE TYPE ty_s_include.");
buildSrc(" TYPES component TYPE i.");
buildSrc(" TYPES END OF ty_s_any_struc.");
buildExp(" TYPES: BEGIN OF ty_s_any_struc.");
buildExp(" INCLUDE TYPE ty_s_include.");
buildExp(" TYPES component TYPE i.");
buildExp(" TYPES END OF ty_s_any_struc.");
testRule();
}
@Test
void testCommentAfterTypesMovedUp() {
buildSrc(" TYPES:");
buildSrc(" \"! documentation");
buildSrc(" BEGIN OF ty_s_any_struc,");
buildSrc(" component TYPE string.");
buildSrc(" INCLUDE TYPE ty_s_include.");
buildSrc(" TYPES END OF ty_s_any_struc.");
buildExp(" TYPES: \"! documentation");
buildExp(" BEGIN OF ty_s_any_struc,");
buildExp(" component TYPE string.");
buildExp(" INCLUDE TYPE ty_s_include.");
buildExp(" TYPES END OF ty_s_any_struc.");
testRule();
}
@Test
void testAsteriskCommentAfterTypesKept() {
buildSrc(" TYPES:");
buildSrc("* comment");
buildSrc(" BEGIN OF ty_s_any_struc,");
buildSrc(" component TYPE string.");
buildSrc(" INCLUDE TYPE ty_s_include.");
buildSrc(" TYPES END OF ty_s_any_struc.");
buildExp(" TYPES:");
buildExp("* comment");
buildExp(" BEGIN OF ty_s_any_struc,");
buildExp(" component TYPE string.");
buildExp(" INCLUDE TYPE ty_s_include.");
buildExp(" TYPES END OF ty_s_any_struc.");
testRule();
}
@Test
void testTypesColonTypesInclude() {
buildSrc(" TYPES:");
buildSrc(" BEGIN OF ty_s_struc.");
buildSrc(" TYPES component TYPE string.");
buildSrc(" INCLUDE TYPE ty_s_include.");
buildSrc(" TYPES END OF ty_s_struc .");
buildExp(" TYPES: BEGIN OF ty_s_struc.");
buildExp(" TYPES component TYPE string.");
buildExp(" INCLUDE TYPE ty_s_include.");
buildExp(" TYPES END OF ty_s_struc .");
testRule();
}
@Test
void testLongNameAfterEndOfStructure() {
// ensure that the alignment of TYPE inside the BEGIN OF ... END OF section
// is NOT influenced by the long identifier after END OF
buildSrc(" TYPES:");
buildSrc(" BEGIN OF ty_s_struc,");
buildSrc(" comp1 TYPE string,");
buildSrc(" component2 TYPE string,");
buildSrc(" END OF ty_s_struc,");
buildSrc(" ty_tt_table_with_long_name TYPE TABLE OF ty_s_struc.");
buildSrc("");
buildSrc(" DATA mv_any TYPE i.");
buildExp(" TYPES:");
buildExp(" BEGIN OF ty_s_struc,");
buildExp(" comp1 TYPE string,");
buildExp(" component2 TYPE string,");
buildExp(" END OF ty_s_struc,");
buildExp(" ty_tt_table_with_long_name TYPE TABLE OF ty_s_struc.");
buildExp("");
buildExp(" DATA mv_any TYPE i.");
testRule();
}
@Test
void testAlignAllInnerStructures() {
rule.configStructureAlignStyle.setEnumValue(StructureAlignStyle.ACROSS_LEVELS);
// expect everything within one structure to be aligned, including TYPE sections of enclosed structures
buildSrc(" TYPES:");
buildSrc(" BEGIN OF ty_s_outer,");
buildSrc(" one TYPE i,");
buildSrc(" two TYPE i,");
buildSrc(" BEGIN OF ty_s_inner,");
buildSrc(" a1 TYPE i,");
buildSrc(" b2 TYPE i,");
buildSrc(" c3 TYPE i,");
buildSrc(" END OF ty_s_inner,");
buildSrc(" three TYPE i,");
buildSrc(" four TYPE i,");
buildSrc(" BEGIN OF ty_s_another_inner,");
buildSrc(" long_component_name TYPE i,");
buildSrc(" very_long_component_name TYPE i,");