1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.puppycrawl.tools.checkstyle.checks.whitespace;
21
22 import static com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck.MSG_WS_NOT_FOLLOWED;
23 import static com.puppycrawl.tools.checkstyle.checks.whitespace.WhitespaceAroundCheck.MSG_WS_NOT_PRECEDED;
24
25 import org.junit.jupiter.api.Test;
26
27 import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
28
29 public class WhitespaceAroundExamplesTest extends AbstractExamplesModuleTestSupport {
30
31 @Override
32 public String getPackageLocation() {
33 return "com/puppycrawl/tools/checkstyle/checks/whitespace/whitespacearound";
34 }
35
36 @Test
37 public void testExample1() throws Exception {
38 final String[] expected = {
39 "11:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
40 "13:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
41 "13:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
42 "19:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "->"),
43 "19:26: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
44 "24:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
45 "28:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
46 "31:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
47 "35:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
48 };
49
50 verifyWithInlineConfigParser(getPath("Example1.java"), expected);
51 }
52
53 @Test
54 public void testExample2() throws Exception {
55 final String[] expected = {
56 "13:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
57 "15:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
58 "15:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
59 "21:26: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
60 "26:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
61 "30:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
62 "33:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
63 "37:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
64 };
65
66 verifyWithInlineConfigParser(getPath("Example2.java"), expected);
67 }
68
69 @Test
70 public void testExample3() throws Exception {
71 final String[] expected = {
72 "13:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
73 "15:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
74 "15:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
75 "21:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "->"),
76 "21:26: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
77 "26:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
78 "30:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
79 "33:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
80 };
81
82 verifyWithInlineConfigParser(getPath("Example3.java"), expected);
83 }
84
85 @Test
86 public void testExample4() throws Exception {
87 final String[] expected = {
88 "13:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
89 "21:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "->"),
90 "21:26: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
91 "26:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
92 "30:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
93 "33:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
94 "37:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
95 };
96
97 verifyWithInlineConfigParser(getPath("Example4.java"), expected);
98 }
99
100 @Test
101 public void testExample5() throws Exception {
102 final String[] expected = {
103 "15:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
104 "15:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
105 "21:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "->"),
106 "21:26: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
107 "26:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
108 "30:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
109 "33:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
110 "37:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
111 };
112
113 verifyWithInlineConfigParser(getPath("Example5.java"), expected);
114 }
115
116 @Test
117 public void testExample6() throws Exception {
118 final String[] expected = {
119 "13:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
120 "15:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
121 "15:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
122 "21:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "->"),
123 "21:26: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
124 "26:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
125 "33:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
126 "37:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
127 };
128
129 verifyWithInlineConfigParser(getPath("Example6.java"), expected);
130 }
131
132 @Test
133 public void testExample7() throws Exception {
134 final String[] expected = {
135 "13:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
136 "15:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
137 "15:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
138 "21:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "->"),
139 "26:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
140 "30:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
141 "33:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
142 "37:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
143 };
144
145 verifyWithInlineConfigParser(getPath("Example7.java"), expected);
146 }
147
148 @Test
149 public void testExample8() throws Exception {
150 final String[] expected = {
151 "13:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
152 "15:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
153 "15:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
154 "21:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "->"),
155 "21:26: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
156 "30:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
157 "33:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
158 "37:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
159 };
160
161 verifyWithInlineConfigParser(getPath("Example8.java"), expected);
162 }
163
164 @Test
165 public void testExample9() throws Exception {
166 final String[] expected = {
167 "13:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
168 "15:21: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
169 "15:22: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
170 "21:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "->"),
171 "21:26: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
172 "26:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
173 "29:19: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ":"),
174 "30:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
175 "33:14: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
176 "37:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
177 };
178
179 verifyWithInlineConfigParser(getPath("Example9.java"), expected);
180 }
181
182 @Test
183 public void testExample10() throws Exception {
184 final String[] expected = {
185 "13:18: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
186 "15:22: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "{"),
187 "15:23: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "}"),
188 "21:24: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "->"),
189 "21:26: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
190 "26:24: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
191 "30:33: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
192 "37:20: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "{"),
193 };
194
195 verifyWithInlineConfigParser(getPath("Example10.java"), expected);
196 }
197
198 @Test
199 public void testUseCase1() throws Exception {
200 final String[] expected = {
201 "18:10: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "="),
202 "18:10: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "="),
203 "24:6: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "*="),
204 "24:6: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "*="),
205 "29:6: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "-="),
206 "29:6: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "-="),
207 "34:6: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "/="),
208 "34:6: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "/="),
209 "39:6: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, "%="),
210 "39:6: " + getCheckMessage(MSG_WS_NOT_PRECEDED, "%="),
211 "44:6: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, ">>="),
212 "44:6: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ">>="),
213 "49:6: " + getCheckMessage(MSG_WS_NOT_FOLLOWED, ">>>="),
214 "49:6: " + getCheckMessage(MSG_WS_NOT_PRECEDED, ">>>="),
215 };
216
217 verifyWithInlineConfigParser(getPath("UseCase1.java"), expected);
218 }
219
220 }