1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.checkstyle.suppressionxpathfilter.whitespace;
21
22 import java.io.File;
23 import java.util.Collections;
24 import java.util.List;
25
26 import org.checkstyle.suppressionxpathfilter.AbstractXpathTestSupport;
27 import org.junit.jupiter.api.Test;
28
29 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
30 import com.puppycrawl.tools.checkstyle.checks.whitespace.SingleSpaceSeparatorCheck;
31
32 public class XpathRegressionSingleSpaceSeparatorTest extends AbstractXpathTestSupport {
33
34 private final String checkName = SingleSpaceSeparatorCheck.class.getSimpleName();
35
36 @Override
37 protected String getCheckName() {
38 return checkName;
39 }
40
41 @Override
42 protected String getPackageLocation() {
43 return "org/checkstyle/suppressionxpathfilter/whitespace/singlespaceseparator";
44 }
45
46 @Test
47 public void testSingleSpaceSeparator() throws Exception {
48 final File fileToProcess =
49 new File(getPath("InputXpathSingleSpaceSeparator.java"));
50
51 final DefaultConfiguration moduleConfig =
52 createModuleConfig(SingleSpaceSeparatorCheck.class);
53
54 final String[] expectedViolation = {
55 "4:11: " + getCheckMessage(SingleSpaceSeparatorCheck.class,
56 SingleSpaceSeparatorCheck.MSG_KEY),
57 };
58
59 final List<String> expectedXpathQueries = Collections.singletonList(
60 "/COMPILATION_UNIT/CLASS_DEF"
61 + "[./IDENT[@text='InputXpathSingleSpaceSeparator']]/OBJBLOCK"
62 + "/VARIABLE_DEF/IDENT[@text='bad']"
63 );
64
65 runVerifications(moduleConfig, fileToProcess, expectedViolation,
66 expectedXpathQueries);
67 }
68
69 @Test
70 public void testValidateComments() throws Exception {
71 final File fileToProcess = new File(getPath(
72 "InputXpathSingleSpaceSeparatorValidateComments.java"
73 ));
74
75 final DefaultConfiguration moduleConfig =
76 createModuleConfig(SingleSpaceSeparatorCheck.class);
77 moduleConfig.addProperty("validateComments", "true");
78
79 final String[] expectedViolation = {
80 "4:17: " + getCheckMessage(SingleSpaceSeparatorCheck.class,
81 SingleSpaceSeparatorCheck.MSG_KEY),
82 };
83
84 final List<String> expectedXpathQueries = Collections.singletonList(
85 "/COMPILATION_UNIT/CLASS_DEF[."
86 + "/IDENT[@text='InputXpathSingleSpaceSeparatorValidateComments']]"
87 + "/OBJBLOCK/SINGLE_LINE_COMMENT[./COMMENT_CONTENT"
88 + "[@text=' an invalid comment // warn\\n']]"
89 );
90
91 runVerifications(moduleConfig, fileToProcess, expectedViolation,
92 expectedXpathQueries);
93 }
94 }