1
1
package com .sap .adt .abapcleaner .rules .spaces ;
2
2
3
+ import org .junit .jupiter .api .BeforeEach ;
3
4
import org .junit .jupiter .api .Test ;
4
5
5
6
import com .sap .adt .abapcleaner .rulebase .RuleID ;
6
7
import com .sap .adt .abapcleaner .rulebase .RuleTestBase ;
7
8
8
9
class SpacesInEmptyBracketsTest extends RuleTestBase {
10
+ private SpacesInEmptyBracketsRule rule ;
11
+
9
12
SpacesInEmptyBracketsTest () {
10
13
super (RuleID .SPACES_IN_EMPTY_BRACKETS );
14
+ rule = (SpacesInEmptyBracketsRule )getRule ();
15
+ }
16
+
17
+ @ BeforeEach
18
+ void setUp () {
19
+ // setup default test configuration (may be modified in the individual test methods)
20
+ rule .configRemoveMultiSpaceIfEmpty .setValue (true );
21
+ rule .configSeparateFromCharLiterals .setValue (true );
22
+ rule .configSeparateCondensedCases .setValue (false );
11
23
}
12
24
13
25
@ Test
@@ -21,6 +33,19 @@ void testMethodChain() {
21
33
testRule ();
22
34
}
23
35
36
+ @ Test
37
+ void testMethodChainUnchanged () {
38
+ rule .configRemoveMultiSpaceIfEmpty .setValue (false );
39
+
40
+ buildSrc (" ev_result = class_name( )=>get_tool( )->get_value( )." );
41
+
42
+ copyExpFromSrc ();
43
+
44
+ putAnyMethodAroundSrcAndExp ();
45
+
46
+ testRule ();
47
+ }
48
+
24
49
@ Test
25
50
void testCommentLineInsideCommand () {
26
51
buildSrc (" class_name( )=>get_tool(" );
@@ -49,4 +74,188 @@ void testLineBreaksNotRemoved() {
49
74
50
75
testRule ();
51
76
}
77
+
78
+ @ Test
79
+ void testTextFieldLiterals () {
80
+ buildSrc (" any_method( 'text field literal' )." );
81
+ buildSrc (" any_method('other literal' )." );
82
+ buildSrc (" any_method( 'third literal')." );
83
+ buildSrc ("" );
84
+ buildSrc (" lt_any_table = VALUE #( ( CONV #( '11.11') )" );
85
+ buildSrc (" ( CONV #('22.22' ) )" );
86
+ buildSrc (" ( CONV #( '33.33') ) )." );
87
+
88
+ buildExp (" any_method( 'text field literal' )." );
89
+ buildExp (" any_method( 'other literal' )." );
90
+ buildExp (" any_method( 'third literal' )." );
91
+ buildExp ("" );
92
+ buildExp (" lt_any_table = VALUE #( ( CONV #( '11.11' ) )" );
93
+ buildExp (" ( CONV #( '22.22' ) )" );
94
+ buildExp (" ( CONV #( '33.33' ) ) )." );
95
+
96
+ putAnyMethodAroundSrcAndExp ();
97
+
98
+ testRule ();
99
+ }
100
+
101
+ @ Test
102
+ void testTextFieldLiteralsUnchanged () {
103
+ rule .configSeparateFromCharLiterals .setValue (false );
104
+
105
+ buildSrc (" any_method( 'text field literal' )." );
106
+ buildSrc (" any_method('other literal' )." );
107
+ buildSrc (" any_method( 'third literal')." );
108
+ buildSrc ("" );
109
+ buildSrc (" lt_any_table = VALUE #( ( CONV #( '11.11') )" );
110
+ buildSrc (" ( CONV #('22.22' ) )" );
111
+ buildSrc (" ( CONV #('33.33') ) )." );
112
+
113
+ copyExpFromSrc ();
114
+
115
+ putAnyMethodAroundSrcAndExp ();
116
+
117
+ testRule ();
118
+ }
119
+
120
+ @ Test
121
+ void testDynamicMethodCallUnchanged () {
122
+ // introducing spaces in the following dynamic examples would be a syntax error
123
+ buildSrc (" CALL METHOD ('METHOD_NAME')." );
124
+ buildSrc (" CALL METHOD lo_instance->('METHOD_NAME')." );
125
+ buildSrc ("" );
126
+ buildSrc (" CALL METHOD (`METHOD_NAME`)." );
127
+ buildSrc (" CALL METHOD lo_instance->(`METHOD_NAME`)." );
128
+ buildSrc ("" );
129
+ buildSrc (" ASSIGN ('(FUNC_GRP_NAME)TABLE[]') TO <lt_table>." );
130
+ buildSrc ("" );
131
+ buildSrc (" ls_struc-('COMPONENT_NAME') = 1." );
132
+ buildSrc (" <ls_struc>-('COMPONENT_NAME') = 1." );
133
+ buildSrc (" lt_table[ 1 ]-('COMPONENT_NAME') = 1." );
134
+ buildSrc (" lr_data_ref->('COMPONENT_NAME') = 1." );
135
+
136
+ copyExpFromSrc ();
137
+
138
+ putAnyMethodAroundSrcAndExp ();
139
+
140
+ testRule ();
141
+ }
142
+
143
+ @ Test
144
+ void testTextStringLiterals () {
145
+ buildSrc (" other_method( `text string literal` )." );
146
+ buildSrc (" other_method(`other literal` )." );
147
+ buildSrc (" other_method( `third literal`)." );
148
+ buildSrc ("" );
149
+ buildSrc (" lt_other_table = VALUE #( ( `abc` )" );
150
+ buildSrc (" ( `def`)" );
151
+ buildSrc (" ( `ghi`) )." );
152
+
153
+ buildExp (" other_method( `text string literal` )." );
154
+ buildExp (" other_method( `other literal` )." );
155
+ buildExp (" other_method( `third literal` )." );
156
+ buildExp ("" );
157
+ buildExp (" lt_other_table = VALUE #( ( `abc` )" );
158
+ buildExp (" ( `def` )" );
159
+ buildExp (" ( `ghi` ) )." );
160
+
161
+ putAnyMethodAroundSrcAndExp ();
162
+
163
+ testRule ();
164
+ }
165
+
166
+ @ Test
167
+ void testTextStringLiteralsUnchanged () {
168
+ rule .configSeparateFromCharLiterals .setValue (false );
169
+
170
+ buildSrc (" other_method( `text string literal` )." );
171
+ buildSrc (" other_method(`other literal` )." );
172
+ buildSrc (" other_method( `third literal`)." );
173
+ buildSrc ("" );
174
+ buildSrc (" lt_other_table = VALUE #( ( `abc` )" );
175
+ buildSrc (" ( `def`)" );
176
+ buildSrc (" ( `ghi`) )." );
177
+
178
+ copyExpFromSrc ();
179
+
180
+ putAnyMethodAroundSrcAndExp ();
181
+
182
+ testRule ();
183
+ }
184
+
185
+ @ Test
186
+ void testIndentAdjustedForEmptyParens () {
187
+ // expect the indent of the second and third line to be adjusted, but not the indent of the last three lines
188
+ buildSrc (" cl_any_factory=>get( )->get_utility( )->any_method( iv_any_param = 1" );
189
+ buildSrc (" iv_other_param = 2" );
190
+ buildSrc (" iv_third_param = 3 )." );
191
+
192
+ buildExp (" cl_any_factory=>get( )->get_utility( )->any_method( iv_any_param = 1" );
193
+ buildExp (" iv_other_param = 2" );
194
+ buildExp (" iv_third_param = 3 )." );
195
+
196
+ testRule ();
197
+ }
198
+
199
+ @ Test
200
+ void testIndentAdjustedForAttachedLiterals () {
201
+ // expect the indent of the second and third line to be adjusted, but not the indent of the last three lines
202
+ buildSrc (" cl_any_factory=>get( )->get_utility( )->any_method( iv_any_param = 1" );
203
+ buildSrc (" iv_other_param = 2" );
204
+ buildSrc (" iv_third_param = 3 )." );
205
+ buildSrc ("" );
206
+ buildSrc (" cl_any_factory=>get( )->get_utility( )->any_method(" );
207
+ buildSrc (" iv_any_param = 1" );
208
+ buildSrc (" iv_other_param = 2" );
209
+ buildSrc (" iv_third_param = 3 )." );
210
+
211
+ buildExp (" cl_any_factory=>get( )->get_utility( )->any_method( iv_any_param = 1" );
212
+ buildExp (" iv_other_param = 2" );
213
+ buildExp (" iv_third_param = 3 )." );
214
+ buildExp ("" );
215
+ buildExp (" cl_any_factory=>get( )->get_utility( )->any_method(" );
216
+ buildExp (" iv_any_param = 1" );
217
+ buildExp (" iv_other_param = 2" );
218
+ buildExp (" iv_third_param = 3 )." );
219
+
220
+ testRule ();
221
+ }
222
+
223
+ @ Test
224
+ void testKeepCondensedCases () {
225
+ buildSrc (" any_method('text field literal')." );
226
+ buildSrc (" other_method(`text string literal`)." );
227
+ buildSrc ("" );
228
+ buildSrc (" lt_amount = VALUE #( ( CONV #('11.11') )" );
229
+ buildSrc (" ( CONV #('22.22') )" );
230
+ buildSrc (" ( CONV #('33.33') ) )." );
231
+
232
+ copyExpFromSrc ();
233
+
234
+ putAnyMethodAroundSrcAndExp ();
235
+
236
+ testRule ();
237
+ }
238
+
239
+ @ Test
240
+ void testChangeCondensedCases () {
241
+ rule .configSeparateCondensedCases .setValue (true );
242
+
243
+ buildSrc (" any_method('text field literal')." );
244
+ buildSrc (" other_method(`text string literal`)." );
245
+ buildSrc ("" );
246
+ buildSrc (" lt_amount = VALUE #( ( CONV #('11.11') )" );
247
+ buildSrc (" ( CONV #('22.22') )" );
248
+ buildSrc (" ( CONV #('33.33') ) )." );
249
+
250
+ buildExp (" any_method( 'text field literal' )." );
251
+ buildExp (" other_method( `text string literal` )." );
252
+ buildExp ("" );
253
+ buildExp (" lt_amount = VALUE #( ( CONV #( '11.11' ) )" );
254
+ buildExp (" ( CONV #( '22.22' ) )" );
255
+ buildExp (" ( CONV #( '33.33' ) ) )." );
256
+
257
+ putAnyMethodAroundSrcAndExp ();
258
+
259
+ testRule ();
260
+ }
52
261
}
0 commit comments