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.google.common.truth.Truth.assertWithMessage;
23 import static com.puppycrawl.tools.checkstyle.checks.whitespace.SingleSpaceSeparatorCheck.MSG_KEY;
24
25 import org.junit.jupiter.api.Test;
26
27 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
28 import com.puppycrawl.tools.checkstyle.utils.CommonUtil;
29
30 public class SingleSpaceSeparatorCheckTest extends AbstractModuleTestSupport {
31
32 @Override
33 protected String getPackageLocation() {
34 return "com/puppycrawl/tools/checkstyle/checks/whitespace/singlespaceseparator";
35 }
36
37 @Test
38 public void testNoSpaceErrors() throws Exception {
39 verifyWithInlineConfigParser(
40 getPath("InputSingleSpaceSeparatorNoErrors.java"),
41 CommonUtil.EMPTY_STRING_ARRAY);
42 }
43
44 @Test
45 public void testNoStackoverflowError() throws Exception {
46 verifyWithLimitedResources(getPath("InputSingleSpaceSeparatorNoStackoverflowError.java"),
47 CommonUtil.EMPTY_STRING_ARRAY);
48 }
49
50 @Test
51 public void testGetAcceptableTokens() {
52 final SingleSpaceSeparatorCheck check = new SingleSpaceSeparatorCheck();
53
54 assertWithMessage("Invalid acceptable tokens")
55 .that(check.getAcceptableTokens())
56 .isEqualTo(CommonUtil.EMPTY_INT_ARRAY);
57 }
58
59 @Test
60 public void testSpaceErrors() throws Exception {
61 final String[] expected = {
62 "8:10: " + getCheckMessage(MSG_KEY),
63 "8:28: " + getCheckMessage(MSG_KEY),
64 "11:9: " + getCheckMessage(MSG_KEY),
65 "13:19: " + getCheckMessage(MSG_KEY),
66 "13:52: " + getCheckMessage(MSG_KEY),
67 "14:21: " + getCheckMessage(MSG_KEY),
68 "15:12: " + getCheckMessage(MSG_KEY),
69 "15:16: " + getCheckMessage(MSG_KEY),
70 "18:4: " + getCheckMessage(MSG_KEY),
71 "19:6: " + getCheckMessage(MSG_KEY),
72 "20:8: " + getCheckMessage(MSG_KEY),
73 "21:9: " + getCheckMessage(MSG_KEY),
74 "24:14: " + getCheckMessage(MSG_KEY),
75 "24:24: " + getCheckMessage(MSG_KEY),
76 "24:33: " + getCheckMessage(MSG_KEY),
77 "25:16: " + getCheckMessage(MSG_KEY),
78 "25:23: " + getCheckMessage(MSG_KEY),
79 "26:17: " + getCheckMessage(MSG_KEY),
80 "26:24: " + getCheckMessage(MSG_KEY),
81 "27:20: " + getCheckMessage(MSG_KEY),
82 "28:22: " + getCheckMessage(MSG_KEY),
83 "33:22: " + getCheckMessage(MSG_KEY),
84 "33:28: " + getCheckMessage(MSG_KEY),
85 "34:15: " + getCheckMessage(MSG_KEY),
86 "34:24: " + getCheckMessage(MSG_KEY),
87 "34:32: " + getCheckMessage(MSG_KEY),
88 "34:47: " + getCheckMessage(MSG_KEY),
89 "35:17: " + getCheckMessage(MSG_KEY),
90 "35:23: " + getCheckMessage(MSG_KEY),
91 "37:17: " + getCheckMessage(MSG_KEY),
92 "37:34: " + getCheckMessage(MSG_KEY),
93 "38:8: " + getCheckMessage(MSG_KEY),
94 };
95
96 verifyWithInlineConfigParser(
97 getPath("InputSingleSpaceSeparatorErrors.java"), expected);
98 }
99
100 @Test
101 public void testSpaceErrorsAroundComments() throws Exception {
102 final String[] expected = {
103 "12:11: " + getCheckMessage(MSG_KEY),
104 "12:43: " + getCheckMessage(MSG_KEY),
105 "13:14: " + getCheckMessage(MSG_KEY),
106 "20:14: " + getCheckMessage(MSG_KEY),
107 "20:25: " + getCheckMessage(MSG_KEY),
108 "21:8: " + getCheckMessage(MSG_KEY),
109 };
110
111 verifyWithInlineConfigParser(
112 getPath("InputSingleSpaceSeparatorComments.java"), expected);
113 }
114
115 @Test
116 public void testSpaceErrorsInChildNodes() throws Exception {
117 final String[] expected = {
118 "12:16: " + getCheckMessage(MSG_KEY),
119 };
120
121 verifyWithInlineConfigParser(
122 getPath("InputSingleSpaceSeparatorChildNodes.java"), expected);
123 }
124
125 @Test
126 public void testMinColumnNo() throws Exception {
127 final String[] expected = {
128 "12:4: " + getCheckMessage(MSG_KEY),
129 };
130
131 verifyWithInlineConfigParser(
132 getPath("InputSingleSpaceSeparatorMinColumnNo.java"), expected);
133 }
134
135 @Test
136 public void testWhitespaceInStartOfTheLine() throws Exception {
137 final String[] expected = {
138 "12:7: " + getCheckMessage(MSG_KEY),
139 };
140
141 verifyWithInlineConfigParser(
142 getPath("InputSingleSpaceSeparatorStartOfTheLine.java"), expected);
143 }
144
145 @Test
146 public void testSpaceErrorsIfCommentsIgnored() throws Exception {
147 final String[] expected = {
148 "20:14: " + getCheckMessage(MSG_KEY),
149 };
150
151 verifyWithInlineConfigParser(
152 getPath("InputSingleSpaceSeparatorComments2.java"), expected);
153 }
154
155 @Test
156 public void testEmpty() throws Exception {
157 final String[] expected = CommonUtil.EMPTY_STRING_ARRAY;
158
159 verifyWithInlineConfigParser(
160 getPath("InputSingleSpaceSeparatorEmpty.java"), expected);
161 }
162
163 @Test
164 public void testSpaceErrorsWithEmoji() throws Exception {
165 final String[] expected = {
166 "14:18: " + getCheckMessage(MSG_KEY),
167 "16:17: " + getCheckMessage(MSG_KEY),
168 "18:27: " + getCheckMessage(MSG_KEY),
169 "24:46: " + getCheckMessage(MSG_KEY),
170 "27:9: " + getCheckMessage(MSG_KEY),
171 "33:17: " + getCheckMessage(MSG_KEY),
172 "36:14: " + getCheckMessage(MSG_KEY),
173 "36:25: " + getCheckMessage(MSG_KEY),
174 "36:37: " + getCheckMessage(MSG_KEY),
175 "37:43: " + getCheckMessage(MSG_KEY),
176 "37:46: " + getCheckMessage(MSG_KEY),
177 "38:15: " + getCheckMessage(MSG_KEY),
178 "40:16: " + getCheckMessage(MSG_KEY),
179 };
180 verifyWithInlineConfigParser(
181 getPath("InputSingleSpaceSeparatorWithEmoji.java"), expected);
182 }
183
184 @Test
185 public void testSpaceErrorsAroundCommentsWithEmoji() throws Exception {
186 final String[] expected = {
187 "25:22: " + getCheckMessage(MSG_KEY),
188 "25:26: " + getCheckMessage(MSG_KEY),
189 "26:26: " + getCheckMessage(MSG_KEY),
190 "27:13: " + getCheckMessage(MSG_KEY),
191 "34:8: " + getCheckMessage(MSG_KEY),
192 "36:37: " + getCheckMessage(MSG_KEY),
193 "38:46: " + getCheckMessage(MSG_KEY),
194 "40:24: " + getCheckMessage(MSG_KEY),
195 };
196 verifyWithInlineConfigParser(
197 getPath("InputSingleSpaceSeparatorCommentsWithEmoji.java"), expected);
198 }
199 }