Source code: com/puppycrawl/tools/checkstyle/checks/indentation/IndentationCheckTest.java
1 package com.puppycrawl.tools.checkstyle.checks.indentation;
2
3 import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
4 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
5 import com.puppycrawl.tools.checkstyle.Checker;
6
7 /**
8 *
9 * @author jrichard
10 */
11 public class IndentationCheckTest extends BaseCheckTestCase {
12
13
14 public void testInvalidLabel()
15 throws Exception
16 {
17 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
18 final String[] expected = {
19 "20: label child at indentation level 10 not at correct indentation, 8",
20 "24: label child at indentation level 16 not at correct indentation, 12",
21 "29: label child at indentation level 2 not at correct indentation, 4",
22 "32: label child at indentation level 18 not at correct indentation, 8",
23 "33: ctor def child at indentation level 18 not at correct indentation, 8",
24 "35: label child at indentation level 6 not at correct indentation, 8",
25 "35: method call child at indentation level 6 not at correct indentation, 8",
26 "37: label child at indentation level 6 not at correct indentation, 8",
27 "37: method call child at indentation level 6 not at correct indentation, 8",
28 };
29 verify(checkConfig, getPath("indentation/InputInvalidLabelIndent.java"), expected);
30 }
31
32
33
34 public void testValidLabel()
35 throws Exception
36 {
37 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
38 final String[] expected = {
39 };
40 verify(checkConfig, getPath("indentation/InputValidLabelIndent.java"), expected);
41 }
42
43
44 public void testValidIfWithChecker()
45 throws Exception
46 {
47 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
48 final Checker c = createChecker(checkConfig);
49 final String fname = getPath("indentation/InputValidIfIndent.java");
50 final String[] expected = {
51 };
52 verify(c, fname, expected);
53 }
54
55
56 public void testValidDotWithChecker()
57 throws Exception
58 {
59 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
60 final Checker c = createChecker(checkConfig);
61 final String fname = getPath("indentation/InputValidDotIndent.java");
62 final String[] expected = {
63 };
64 verify(c, fname, expected);
65 }
66
67
68 public void testValidMethodWithChecker()
69 throws Exception
70 {
71 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
72 final Checker c = createChecker(checkConfig);
73 final String fname = getPath("indentation/InputValidMethodIndent.java");
74 final String[] expected = {
75 };
76 verify(c, fname, expected);
77 }
78
79
80 public void testInvalidMethodWithChecker()
81 throws Exception
82 {
83 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
84 final Checker c = createChecker(checkConfig);
85 final String fname = getPath("indentation/InputInvalidMethodIndent.java");
86 final String[] expected = {
87 "17: ctor def rcurly at indentation level 6 not at correct indentation, 4",
88 "20: ctor def modifier at indentation level 6 not at correct indentation, 4",
89 "21: ctor def lcurly at indentation level 2 not at correct indentation, 4",
90 "22: ctor def rcurly at indentation level 6 not at correct indentation, 4",
91 "25: method def modifier at indentation level 2 not at correct indentation, 4",
92 "26: method def rcurly at indentation level 6 not at correct indentation, 4",
93 "63: method def modifier at indentation level 5 not at correct indentation, 4",
94 "64: method def modifier at indentation level 5 not at correct indentation, 4",
95 "65: method def return type at indentation level 5 not at correct indentation, 4",
96 "74: method def modifier at indentation level 3 not at correct indentation, 4",
97 "75: method def modifier at indentation level 3 not at correct indentation, 4",
98 "76: method def return type at indentation level 3 not at correct indentation, 4",
99 "77: method def at indentation level 5 not at correct indentation, 4",
100 "87: ctor def child at indentation level 4 not at correct indentation, 8",
101 "87: method call child at indentation level 4 not at correct indentation, 8",
102 "92: method def child at indentation level 6 not at correct indentation, 8",
103 "93: if at indentation level 6 not at correct indentation, 8",
104 "94: if child at indentation level 10 not at correct indentation, 12",
105 "94: method call child at indentation level 10 not at correct indentation, 12",
106 "95: if rcurly at indentation level 6 not at correct indentation, 8",
107 "98: method call child at indentation level 10 not at correct indentation, 12",
108 "104: method call child at indentation level 14 not at correct indentation, 16",
109 "107: method call child at indentation level 10 not at correct indentation, 12",
110 "112: method call child at indentation level 14 not at correct indentation, 16",
111 "116: method call child at indentation level 10 not at correct indentation, 12",
112 "120: method call child at indentation level 10 not at correct indentation, 12",
113 "121: method call rparen at indentation level 6 not at correct indentation, 8",
114 "125: method call rparen at indentation level 6 not at correct indentation, 8",
115 "139: method call child at indentation level 10 not at correct indentation, 12",
116 "142: method call child at indentation level 10 not at correct indentation, 12",
117 "152: method call child at indentation level 6 not at correct indentation, 12",
118 "158: method def throws at indentation level 6 not at correct indentation, 8",
119 };
120 verify(c, fname, expected);
121 }
122
123
124
125
126 public void testInvalidSwitchWithChecker()
127 throws Exception
128 {
129 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
130 final Checker c = createChecker(checkConfig);
131 final String fname = getPath("indentation/InputInvalidSwitchIndent.java");
132 final String[] expected = {
133 "26: switch at indentation level 6 not at correct indentation, 8",
134 "28: case child at indentation level 10 not at correct indentation, 12",
135 "29: block child at indentation level 14 not at correct indentation, 16",
136 "29: method call child at indentation level 14 not at correct indentation, 16",
137 "33: block child at indentation level 14 not at correct indentation, 16",
138 "35: case child at indentation level 14 not at correct indentation, 12",
139 "36: case child at indentation level 10 not at correct indentation, 12",
140 "39: case child at indentation level 10 not at correct indentation, 12",
141 "40: block child at indentation level 14 not at correct indentation, 16",
142 "40: method call child at indentation level 14 not at correct indentation, 16",
143 "41: block child at indentation level 14 not at correct indentation, 16",
144 "49: block child at indentation level 14 not at correct indentation, 16",
145 "49: method call child at indentation level 14 not at correct indentation, 16",
146 "50: block child at indentation level 18 not at correct indentation, 16",
147 "51: block rcurly at indentation level 10 not at correct indentation, 12",
148 "55: block lcurly at indentation level 10 not at correct indentation, 12",
149 "58: block rcurly at indentation level 14 not at correct indentation, 12",
150 "62: block lcurly at indentation level 14 not at correct indentation, 12",
151 "65: block rcurly at indentation level 10 not at correct indentation, 12",
152 "72: case child at indentation level 14 not at correct indentation, 16",
153 "77: case child at indentation level 14 not at correct indentation, 16",
154 "85: switch rcurly at indentation level 6 not at correct indentation, 8",
155 "88: switch lcurly at indentation level 6 not at correct indentation, 8",
156 "89: switch rcurly at indentation level 10 not at correct indentation, 8",
157 "91: switch lcurly at indentation level 10 not at correct indentation, 8",
158 "92: switch rcurly at indentation level 6 not at correct indentation, 8",
159 };
160 verify(c, fname, expected);
161 }
162
163 public void testValidSwitchWithChecker()
164 throws Exception
165 {
166 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
167 final Checker c = createChecker(checkConfig);
168 final String fname = getPath("indentation/InputValidSwitchIndent.java");
169 final String[] expected = {
170 };
171 verify(c, fname, expected);
172 }
173
174
175
176 public void testValidArrayInitWithChecker()
177 throws Exception
178 {
179 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
180 final Checker c = createChecker(checkConfig);
181 final String fname = getPath("indentation/InputValidArrayInitIndent.java");
182 final String[] expected = {
183 };
184 verify(c, fname, expected);
185 }
186
187 public void testInvalidArrayInitWithChecker()
188 throws Exception
189 {
190 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
191 final Checker c = createChecker(checkConfig);
192 final String fname = getPath("indentation/InputInvalidArrayInitIndent.java");
193 final String[] expected = {
194 "17: class def child at indentation level 2 not at correct indentation, 4",
195 "18: class def child at indentation level 6 not at correct indentation, 4",
196 "20: class def child at indentation level 2 not at correct indentation, 4",
197 "22: array initialization rcurly at indentation level 6 not at correct indentation, 2",
198 "24: class def child at indentation level 6 not at correct indentation, 4",
199 "25: array initialization child at indentation level 8 not at correct indentation, 10",
200 "26: array initialization rcurly at indentation level 4 not at correct indentation, 6",
201 "29: array initialization child at indentation level 9 not at correct indentation, 8",
202 "30: array initialization child at indentation level 7 not at correct indentation, 8",
203 "31: array initialization child at indentation level 9 not at correct indentation, 8",
204 "36: array initialization lcurly at indentation level 2 not at correct indentation, 4",
205 "40: array initialization rcurly at indentation level 6 not at correct indentation, 4",
206 "44: array initialization lcurly at indentation level 2 not at correct indentation, 4",
207 "48: array initialization child at indentation level 20 not at correct indentation, [8, 31]",
208 "49: array initialization child at indentation level 4 not at correct indentation, [8, 31]",
209 "54: array initialization child at indentation level 6 not at correct indentation, 8",
210 "59: class def child at indentation level 2 not at correct indentation, 4",
211 "61: class def child at indentation level 6 not at correct indentation, 4",
212 "62: array initialization rcurly at indentation level 2 not at correct indentation, 6",
213 "65: array initialization child at indentation level 6 not at correct indentation, 8",
214 "72: array initialization child at indentation level 10 not at correct indentation, 12",
215 "85: array initialization child at indentation level 8 not at correct indentation, 12",
216 "96: array initialization child at indentation level 10 not at correct indentation, 12",
217 "97: array initialization child at indentation level 14 not at correct indentation, 12",
218 "100: array initialization child at indentation level 10 not at correct indentation, 12",
219 "101: array initialization child at indentation level 14 not at correct indentation, 12",
220 "102: array initialization rcurly at indentation level 6 not at correct indentation, 8",
221 "105: array initialization lcurly at indentation level 6 not at correct indentation, 8",
222 "106: array initialization child at indentation level 14 not at correct indentation, 12",
223 "107: array initialization child at indentation level 10 not at correct indentation, 12",
224 "108: array initialization rcurly at indentation level 6 not at correct indentation, 8",
225 };
226 verify(c, fname, expected);
227 }
228
229
230
231
232 public void testValidTryWithChecker()
233 throws Exception
234 {
235 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
236 final Checker c = createChecker(checkConfig);
237 final String fname = getPath("indentation/InputValidTryIndent.java");
238 final String[] expected = {
239 };
240 verify(c, fname, expected);
241 }
242
243 public void testInvalidTryWithChecker()
244 throws Exception
245 {
246 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
247 final Checker c = createChecker(checkConfig);
248 final String fname = getPath("indentation/InputInvalidTryIndent.java");
249 final String[] expected = {
250 "21: try at indentation level 9 not at correct indentation, 8",
251 "22: try rcurly at indentation level 7 not at correct indentation, 8",
252 "24: catch rcurly at indentation level 7 not at correct indentation, 8",
253 "26: try at indentation level 4 not at correct indentation, 8",
254 "27: method call child at indentation level 8 not at correct indentation, 12",
255 "27: try child at indentation level 8 not at correct indentation, 12",
256 "28: try rcurly at indentation level 4 not at correct indentation, 8",
257 "29: finally child at indentation level 8 not at correct indentation, 12",
258 "29: method call child at indentation level 8 not at correct indentation, 12",
259 "34: catch child at indentation level 8 not at correct indentation, 12",
260 "34: method call child at indentation level 8 not at correct indentation, 12",
261 "39: try rcurly at indentation level 10 not at correct indentation, 8",
262 "41: catch rcurly at indentation level 6 not at correct indentation, 8",
263 "48: catch rcurly at indentation level 5 not at correct indentation, 8",
264 "55: catch child at indentation level 10 not at correct indentation, 12",
265 "55: method call child at indentation level 10 not at correct indentation, 12",
266 "56: catch child at indentation level 14 not at correct indentation, 12",
267 "57: catch child at indentation level 10 not at correct indentation, 12",
268 "57: method call child at indentation level 10 not at correct indentation, 12",
269 "59: catch at indentation level 6 not at correct indentation, 8",
270 "66: try lcurly at indentation level 10 not at correct indentation, 8",
271 "68: try rcurly at indentation level 10 not at correct indentation, 8",
272 "70: catch lcurly at indentation level 6 not at correct indentation, 8",
273 "73: catch rcurly at indentation level 10 not at correct indentation, 8",
274 "76: catch child at indentation level 10 not at correct indentation, 12",
275 "76: method call child at indentation level 10 not at correct indentation, 12",
276 };
277 verify(c, fname, expected);
278 }
279
280
281 // TODO: needs to be finished
282 public void testInvalidClassDefWithChecker()
283 throws Exception
284 {
285 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
286 final Checker c = createChecker(checkConfig);
287 final String fname = getPath("indentation/InputInvalidClassDefIndent.java");
288 final String[] expected = {
289 "19: class def ident at indentation level 2 not at correct indentation, 0",
290 "19: class def modifier at indentation level 2 not at correct indentation, 0",
291 "25: class def lcurly at indentation level 2 not at correct indentation, 0",
292 "28: class def rcurly at indentation level 2 not at correct indentation, 0",
293 "31: class def ident at indentation level 2 not at correct indentation, 0",
294 "35: class def rcurly at indentation level 2 not at correct indentation, 0",
295 "40: class def child at indentation level 2 not at correct indentation, 4",
296 "41: class def child at indentation level 2 not at correct indentation, 4",
297 "47: class def child at indentation level 2 not at correct indentation, 4",
298 "55: class def child at indentation level 2 not at correct indentation, 4",
299 "56: class def child at indentation level 2 not at correct indentation, 4",
300 "61: class def ident at indentation level 2 not at correct indentation, 0",
301 "61: class def modifier at indentation level 2 not at correct indentation, 0",
302 "62: class def lcurly at indentation level 2 not at correct indentation, 0",
303 "70: class def rcurly at indentation level 2 not at correct indentation, 0",
304 "74: class def child at indentation level 2 not at correct indentation, 4",
305 "83: class def child at indentation level 2 not at correct indentation, 4",
306 "83: class def ident at indentation level 2 not at correct indentation, 4",
307 "85: class def ident at indentation level 6 not at correct indentation, 4",
308 "88: class def child at indentation level 2 not at correct indentation, 4",
309 "88: class def ident at indentation level 2 not at correct indentation, 4",
310 "92: class def child at indentation level 6 not at correct indentation, 8",
311 "98: class def child at indentation level 10 not at correct indentation, 12",
312 "103: class def child at indentation level 6 not at correct indentation, 8",
313 "108: class def rcurly at indentation level 6 not at correct indentation, 4",
314 "110: class def ident at indentation level 6 not at correct indentation, 4",
315 "116: class def child at indentation level 6 not at correct indentation, 8",
316 "116: class def ident at indentation level 6 not at correct indentation, 8",
317 "119: class def ident at indentation level 10 not at correct indentation, 8",
318 "121: class def rcurly at indentation level 10 not at correct indentation, 8",
319 "124: class def child at indentation level 10 not at correct indentation, 12",
320 "129: method def child at indentation level 10 not at correct indentation, 8",
321 "138: object def lcurly at indentation level 6 not at correct indentation, 8",
322 "142: object def rcurly at indentation level 6 not at correct indentation, 8",
323 "147: method def modifier at indentation level 10 not at correct indentation, 12",
324 "149: method def rcurly at indentation level 10 not at correct indentation, 12",
325 // TODO: extends and implements need to be added
326 };
327 verify(c, fname, expected);
328 }
329
330
331 public void testInvalidBlockWithChecker()
332 throws Exception
333 {
334 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
335 final Checker c = createChecker(checkConfig);
336 final String fname = getPath("indentation/InputInvalidBlockIndent.java");
337 final String[] expected = {
338 "22: block lcurly at indentation level 7 not at correct indentation, 8",
339 "23: block lcurly at indentation level 9 not at correct indentation, 8",
340 "25: block lcurly at indentation level 9 not at correct indentation, 8",
341 "26: block rcurly at indentation level 7 not at correct indentation, 8",
342 "28: block lcurly at indentation level 6 not at correct indentation, 8",
343 "30: block rcurly at indentation level 6 not at correct indentation, 8",
344 "31: block lcurly at indentation level 6 not at correct indentation, 8",
345 "34: block lcurly at indentation level 9 not at correct indentation, 8",
346 "35: block child at indentation level 13 not at correct indentation, 12",
347 "37: block child at indentation level 13 not at correct indentation, 12",
348 "38: block rcurly at indentation level 9 not at correct indentation, 8",
349 "41: block lcurly at indentation level 6 not at correct indentation, 8",
350 "42: block child at indentation level 10 not at correct indentation, 12",
351 "44: block child at indentation level 10 not at correct indentation, 12",
352 "45: block rcurly at indentation level 6 not at correct indentation, 8",
353 "48: block lcurly at indentation level 6 not at correct indentation, 8",
354 "51: block child at indentation level 10 not at correct indentation, 12",
355 "55: block lcurly at indentation level 10 not at correct indentation, 12",
356 "59: block rcurly at indentation level 10 not at correct indentation, 12",
357 "64: block child at indentation level 10 not at correct indentation, 12",
358 "66: block lcurly at indentation level 10 not at correct indentation, 12",
359 "67: block child at indentation level 14 not at correct indentation, 16",
360 "82: block rcurly at indentation level 10 not at correct indentation, 12",
361 "91: static initialization at indentation level 2 not at correct indentation, 4",
362 "92: static initialization at indentation level 6 not at correct indentation, 4",
363 "96: static initialization child at indentation level 7 not at correct indentation, 8",
364 "99: static initialization at indentation level 6 not at correct indentation, 4",
365 "101: static initialization rcurly at indentation level 2 not at correct indentation, 4",
366 "103: static initialization at indentation level 2 not at correct indentation, 4",
367 "105: static initialization rcurly at indentation level 6 not at correct indentation, 4",
368 "107: static initialization at indentation level 2 not at correct indentation, 4",
369 "109: static initialization child at indentation level 6 not at correct indentation, 8",
370 "112: static initialization lcurly at indentation level 2 not at correct indentation, 4",
371 "113: static initialization child at indentation level 6 not at correct indentation, 8",
372 "114: static initialization rcurly at indentation level 6 not at correct indentation, 4",
373 "119: static initialization child at indentation level 6 not at correct indentation, 8",
374 "124: static initialization child at indentation level 4 not at correct indentation, 8",
375 "125: static initialization rcurly at indentation level 2 not at correct indentation, 4",
376 "130: static initialization rcurly at indentation level 6 not at correct indentation, 4",
377 "133: block lcurly at indentation level 2 not at correct indentation, 4",
378 "134: block lcurly at indentation level 6 not at correct indentation, 4",
379 "137: block lcurly at indentation level 2 not at correct indentation, 4",
380 "139: block rcurly at indentation level 6 not at correct indentation, 4",
381 "141: block lcurly at indentation level 6 not at correct indentation, 4",
382 "143: block rcurly at indentation level 2 not at correct indentation, 4",
383 "146: block child at indentation level 6 not at correct indentation, 8",
384
385 };
386 verify(c, fname, expected);
387 }
388
389 public void testInvalidIfWithChecker()
390 throws Exception
391 {
392 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
393 final Checker c = createChecker(checkConfig);
394 final String fname = getPath("indentation/InputInvalidIfIndent.java");
395 final String[] expected = {
396 "50: if at indentation level 1 not at correct indentation, 8",
397 "55: if at indentation level 9 not at correct indentation, 8",
398 "56: if lcurly at indentation level 9 not at correct indentation, 8",
399 "57: if rcurly at indentation level 7 not at correct indentation, 8",
400 "59: if at indentation level 6 not at correct indentation, 8",
401 "60: if lcurly at indentation level 5 not at correct indentation, 8",
402 "61: if rcurly at indentation level 5 not at correct indentation, 8",
403 "65: if rcurly at indentation level 10 not at correct indentation, 8",
404 "66: else rcurly at indentation level 7 not at correct indentation, 8",
405 "69: if at indentation level 9 not at correct indentation, 8",
406 "70: if lcurly at indentation level 7 not at correct indentation, 8",
407 "72: else at indentation level 9 not at correct indentation, 8",
408 "74: else rcurly at indentation level 9 not at correct indentation, 8",
409 "77: if at indentation level 10 not at correct indentation, 8",
410 "78: if rcurly at indentation level 7 not at correct indentation, 8",
411 "79: else at indentation level 9 not at correct indentation, 8",
412 "80: else lcurly at indentation level 7 not at correct indentation, 8",
413 "81: else rcurly at indentation level 9 not at correct indentation, 8",
414 "85: if at indentation level 9 not at correct indentation, 8",
415 "86: if lcurly at indentation level 9 not at correct indentation, 8",
416 "87: if rcurly at indentation level 9 not at correct indentation, 8",
417 "88: else lcurly at indentation level 7 not at correct indentation, 8",
418 "89: else rcurly at indentation level 10 not at correct indentation, 8",
419 "92: if at indentation level 6 not at correct indentation, 8",
420 "93: if lcurly at indentation level 10 not at correct indentation, 8",
421 "94: if rcurly at indentation level 10 not at correct indentation, 8",
422 "95: else rcurly at indentation level 7 not at correct indentation, 8",
423 "98: if at indentation level 5 not at correct indentation, 8",
424 "99: if rcurly at indentation level 11 not at correct indentation, 8",
425 "100: else at indentation level 5 not at correct indentation, 8",
426 "101: else rcurly at indentation level 11 not at correct indentation, 8",
427 // "110: dot left side \"System\" at indentation level 14 not at correct indentation, 12",
428 "121: if child at indentation level 14 not at correct indentation, 12",
429 "126: if lcurly at indentation level 10 not at correct indentation, 8",
430 "127: if child at indentation level 10 not at correct indentation, 12",
431 "127: method call child at indentation level 10 not at correct indentation, 12",
432 "132: if child at indentation level 14 not at correct indentation, 12",
433 // TODO: should be 16, not 12
434 "133: method call child at indentation level 10 not at correct indentation, 12",
435 "135: else child at indentation level 10 not at correct indentation, 12",
436 // TODO: why we get this message (it's duplicate of previous).
437 "135: method call child at indentation level 10 not at correct indentation, 12",
438 "136: method call child at indentation level 8 not at correct indentation, 12",
439 "143: if child at indentation level 16 not at correct indentation, 12",
440 "144: if rcurly at indentation level 9 not at correct indentation, 8",
441 "147: else child at indentation level 16 not at correct indentation, 12",
442 "153: if child at indentation level 0 not at correct indentation, 12",
443 "153: method call child at indentation level 0 not at correct indentation, 12",
444 "157: else child at indentation level 40 not at correct indentation, 12",
445 "164: if child at indentation level 14 not at correct indentation, 12",
446 "167: else child at indentation level 14 not at correct indentation, 12",
447 "173: if child at indentation level 10 not at correct indentation, 12",
448 "173: method call child at indentation level 10 not at correct indentation, 12",
449 "175: else child at indentation level 10 not at correct indentation, 12",
450 "175: method call child at indentation level 10 not at correct indentation, 12",
451 "179: if at indentation level 10 not at correct indentation, 8",
452 "180: if child at indentation level 14 not at correct indentation, 12",
453 "181: if rcurly at indentation level 10 not at correct indentation, 8",
454 "182: else at indentation level 10 not at correct indentation, 8",
455 "183: else child at indentation level 14 not at correct indentation, 12",
456 "184: else rcurly at indentation level 10 not at correct indentation, 8",
457 "187: if child at indentation level 9 not at correct indentation, 12",
458 "188: if child at indentation level 11 not at correct indentation, 12",
459 "192: if child at indentation level 10 not at correct indentation, 12",
460 "195: if rcurly at indentation level 7 not at correct indentation, 8",
461 "202: if child at indentation level 10 not at correct indentation, 12",
462 "202: method call child at indentation level 10 not at correct indentation, 12",
463 "204: if child at indentation level 10 not at correct indentation, 12",
464 "204: method call child at indentation level 10 not at correct indentation, 12",
465 "211: method call child at indentation level 10 not at correct indentation, 12",
466 "220: if at indentation level 10 not at correct indentation, 12",
467 "224: if child at indentation level 18 not at correct indentation, 20",
468 "224: method call child at indentation level 18 not at correct indentation, 20",
469 "228: if rcurly at indentation level 40 not at correct indentation, 8",
470 "235: if rparen at indentation level 10 not at correct indentation, 8",
471 "240: if rparen at indentation level 6 not at correct indentation, 8",
472 "246: if lparen at indentation level 6 not at correct indentation, 8",
473 "248: if rparen at indentation level 6 not at correct indentation, 8",
474 };
475 verify(c, fname, expected);
476 }
477
478 public void testInvalidWhileWithChecker()
479 throws Exception
480 {
481 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
482 final Checker c = createChecker(checkConfig);
483 final String fname = getPath("indentation/InputInvalidWhileIndent.java");
484 final String[] expected = {
485 "21: while at indentation level 9 not at correct indentation, 8",
486 "22: while rcurly at indentation level 7 not at correct indentation, 8",
487 "24: while at indentation level 7 not at correct indentation, 8",
488 "25: while lcurly at indentation level 9 not at correct indentation, 8",
489 "26: while rcurly at indentation level 9 not at correct indentation, 8",
490 "28: while at indentation level 9 not at correct indentation, 8",
491 "29: while lcurly at indentation level 6 not at correct indentation, 8",
492 "30: while child at indentation level 14 not at correct indentation, 12",
493 "31: while rcurly at indentation level 6 not at correct indentation, 8",
494 "33: while at indentation level 10 not at correct indentation, 8",
495 "35: while rcurly at indentation level 10 not at correct indentation, 8",
496 "37: while at indentation level 10 not at correct indentation, 8",
497 "40: while rcurly at indentation level 10 not at correct indentation, 8",
498 "42: while at indentation level 6 not at correct indentation, 8",
499 "43: while lcurly at indentation level 10 not at correct indentation, 8",
500 "46: while rcurly at indentation level 6 not at correct indentation, 8",
501 "49: if at indentation level 14 not at correct indentation, 12",
502 "50: if child at indentation level 18 not at correct indentation, 16",
503 "51: if rcurly at indentation level 14 not at correct indentation, 12",
504 "52: while child at indentation level 14 not at correct indentation, 12",
505 "53: while rcurly at indentation level 10 not at correct indentation, 8",
506 "56: while child at indentation level 10 not at correct indentation, 12",
507 "62: while child at indentation level 10 not at correct indentation, 12",
508 "67: while child at indentation level 10 not at correct indentation, 12",
509 "74: while rparen at indentation level 5 not at correct indentation, 8",
510 "81: while rparen at indentation level 10 not at correct indentation, 8",
511 "88: while rparen at indentation level 10 not at correct indentation, 8",
512 };
513 verify(c, fname, expected);
514 }
515
516 public void testInvalidForWithChecker()
517 throws Exception
518 {
519 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
520 final Checker c = createChecker(checkConfig);
521 final String fname = getPath("indentation/InputInvalidForIndent.java");
522 final String[] expected = {
523 "22: for at indentation level 6 not at correct indentation, 8",
524 "23: for rcurly at indentation level 10 not at correct indentation, 8",
525 "25: for at indentation level 9 not at correct indentation, 8",
526 "26: for lcurly at indentation level 6 not at correct indentation, 8",
527 "27: for rcurly at indentation level 6 not at correct indentation, 8",
528 "31: for child at indentation level 10 not at correct indentation, 12",
529 "31: method call child at indentation level 10 not at correct indentation, 12",
530 "32: for rcurly at indentation level 10 not at correct indentation, 8",
531 "35: for lcurly at indentation level 10 not at correct indentation, 8",
532 "36: for child at indentation level 10 not at correct indentation, 12",
533 "44: for child at indentation level 10 not at correct indentation, 12",
534 "50: for at indentation level 7 not at correct indentation, 8",
535 "51: for child at indentation level 10 not at correct indentation, 12",
536 "60: for child at indentation level 7 not at correct indentation, 12",
537 "65: for at indentation level 6 not at correct indentation, 8",
538 "66: for child at indentation level 10 not at correct indentation, 12",
539 "67: for child at indentation level 14 not at correct indentation, 16",
540 "68: for child at indentation level 10 not at correct indentation, 12",
541 "73: for rcurly at indentation level 39 not at correct indentation, 8",
542 "77: for rparen at indentation level 12 not at correct indentation, 8",
543 };
544 verify(c, fname, expected);
545 }
546
547 public void testValidForWithChecker()
548 throws Exception
549 {
550 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
551 final Checker c = createChecker(checkConfig);
552 final String fname = getPath("indentation/InputValidForIndent.java");
553 final String[] expected = {
554 };
555 verify(c, fname, expected);
556 }
557
558 public void testValidDoWhileWithChecker()
559 throws Exception
560 {
561 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
562 final Checker c = createChecker(checkConfig);
563 final String fname = getPath("indentation/InputValidDoWhileIndent.java");
564 final String[] expected = {
565 };
566 verify(c, fname, expected);
567 }
568
569 public void testValidBlockWithChecker()
570 throws Exception
571 {
572 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
573 final Checker c = createChecker(checkConfig);
574 final String fname = getPath("indentation/InputValidBlockIndent.java");
575 final String[] expected = {
576 };
577 verify(c, fname, expected);
578 }
579
580
581 public void testValidWhileWithChecker()
582 throws Exception
583 {
584 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
585 final Checker c = createChecker(checkConfig);
586 final String fname = getPath("indentation/InputValidWhileIndent.java");
587 final String[] expected = {
588 };
589 verify(c, fname, expected);
590 }
591
592 public void testValidClassDefWithChecker()
593 throws Exception
594 {
595 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
596 final Checker c = createChecker(checkConfig);
597 final String fname = getPath("indentation/InputValidClassDefIndent.java");
598 final String[] expected = {
599 };
600 verify(c, fname, expected);
601 }
602
603 public void testValidInterfaceDefWithChecker()
604 throws Exception
605 {
606 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
607 final Checker c = createChecker(checkConfig);
608 final String fname = getPath("indentation/InputValidInterfaceDefIndent.java");
609 final String[] expected = {
610 };
611 verify(c, fname, expected);
612 }
613
614 public void testValidCommaWithChecker()
615 throws Exception
616 {
617
618 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
619 final Checker c = createChecker(checkConfig);
620 final String fname = getPath("indentation/InputValidCommaIndent.java");
621 final String[] expected = {
622 };
623 verify(c, fname, expected);
624 }
625
626 public void testTabs()
627 throws Exception
628 {
629 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
630 checkConfig.addAttribute("basicOffset", new Integer(4).toString());
631 checkConfig.addAttribute("tabWidth", new Integer(4).toString());
632 final String[] expected = {
633 "25: ctor def child at indentation level 9 not at correct indentation, 8",
634 };
635 verify(checkConfig, getPath("indentation/InputUseTabs.java"), expected);
636 }
637
638 public void testIndentationLevel()
639 throws Exception
640 {
641 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
642 checkConfig.addAttribute("basicOffset", new Integer(2).toString());
643 final String[] expected = {
644 "25: ctor def child at indentation level 5 not at correct indentation, 4",
645 };
646 verify(checkConfig, getPath("indentation/InputUseTwoSpaces.java"), expected);
647 }
648
649 public void testCaseLevel()
650 throws Exception
651 {
652 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
653 checkConfig.addAttribute("caseIndent", new Integer(0).toString());
654 final String[] expected = {
655 "23: case child at indentation level 10 not at correct indentation, 8",
656 };
657 verify(checkConfig, getPath("indentation/InputCaseLevel.java"), expected);
658 }
659
660 public void testBraceAdjustment()
661 throws Exception
662 {
663 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
664 checkConfig.addAttribute("braceAdjustment", new Integer(2).toString());
665 final String[] expected = {
666 "24: if rcurly at indentation level 8 not at correct indentation, 10",
667 };
668 verify(checkConfig, getPath("indentation/InputBraceAdjustment.java"), expected);
669 }
670
671 public void testInvalidAssignWithChecker() throws Exception
672 {
673 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
674 final String[] expected = {
675 "6: method call child at indentation level 10 not at correct indentation, 12",
676 "8: method call child at indentation level 10 not at correct indentation, 12",
677 "10: method call child at indentation level 10 not at correct indentation, 12",
678 "12: assign at indentation level 9 not at correct indentation, 12",
679 "13: assign child at indentation level 10 not at correct indentation, 12",
680 };
681 verify(checkConfig, getPath("indentation/InputInvalidAssignIndent.java"), expected);
682 }
683
684 public void testValidAssignWithChecker() throws Exception
685 {
686 final DefaultConfiguration checkConfig = createCheckConfig(IndentationCheck.class);
687 final String[] expected = {};
688 verify(checkConfig, getPath("indentation/InputValidAssignIndent.java"), expected);
689 }
690 }