1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package org.checkstyle.suppressionxpathfilter;
21
22 import java.io.File;
23 import java.util.Arrays;
24 import java.util.List;
25
26 import org.junit.jupiter.api.Test;
27
28 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
29 import com.puppycrawl.tools.checkstyle.checks.NumericalPrefixesInfixesSuffixesCharacterCaseCheck;
30
31 public class XpathRegressionNumericalPrefixesInfixesSuffixesCharacterCaseTest
32 extends AbstractXpathTestSupport {
33
34 private final String checkName =
35 NumericalPrefixesInfixesSuffixesCharacterCaseCheck.class.getSimpleName();
36
37 @Override
38 protected String getCheckName() {
39 return checkName;
40 }
41
42 @Test
43 public void testIntLiteralPrefix() throws Exception {
44 final File fileProcess =
45 new File(getPath("InputXpathNumericalPrefixesInfixesSuffixesCharacterCaseOne.java"));
46 final DefaultConfiguration config =
47 createModuleConfig(NumericalPrefixesInfixesSuffixesCharacterCaseCheck.class);
48
49 final String[] expected = {
50 "4:13: " + getCheckMessage(
51 NumericalPrefixesInfixesSuffixesCharacterCaseCheck.class,
52 NumericalPrefixesInfixesSuffixesCharacterCaseCheck.MSG_PREFIX),
53 };
54
55 final List<String> expectedXpathQueries = Arrays.asList(
56 "/COMPILATION_UNIT/CLASS_DEF"
57 + "[./IDENT[@text='InputXpathNumericalPrefixesInfixesSuffixesCharacterCaseOne']]"
58 + "/OBJBLOCK/VARIABLE_DEF"
59 + "[./IDENT[@text='a']]/ASSIGN/EXPR"
60 + "[./NUM_INT[@text='0X1A']]",
61
62 "/COMPILATION_UNIT/CLASS_DEF"
63 + "[./IDENT[@text='InputXpathNumericalPrefixesInfixesSuffixesCharacterCaseOne']]"
64 + "/OBJBLOCK/VARIABLE_DEF"
65 + "[./IDENT[@text='a']]/ASSIGN/EXPR"
66 + "/NUM_INT[@text='0X1A']"
67 );
68
69 runVerifications(config, fileProcess, expected, expectedXpathQueries);
70 }
71
72 @Test
73 public void testLongLiteralPrefix() throws Exception {
74 final File fileProcess =
75 new File(getPath("InputXpathNumericalPrefixesInfixesSuffixesCharacterCaseTwo.java"));
76 final DefaultConfiguration config =
77 createModuleConfig(NumericalPrefixesInfixesSuffixesCharacterCaseCheck.class);
78
79 final String[] expected = {
80 "4:14: " + getCheckMessage(
81 NumericalPrefixesInfixesSuffixesCharacterCaseCheck.class,
82 NumericalPrefixesInfixesSuffixesCharacterCaseCheck.MSG_PREFIX),
83 };
84
85 final List<String> expectedXpathQueries = Arrays.asList(
86 "/COMPILATION_UNIT/CLASS_DEF"
87 + "[./IDENT[@text='InputXpathNumericalPrefixesInfixesSuffixesCharacterCaseTwo']]"
88 + "/OBJBLOCK/VARIABLE_DEF"
89 + "[./IDENT[@text='a']]/ASSIGN/EXPR"
90 + "[./NUM_LONG[@text='0X10L']]",
91
92 "/COMPILATION_UNIT/CLASS_DEF"
93 + "[./IDENT[@text='InputXpathNumericalPrefixesInfixesSuffixesCharacterCaseTwo']]"
94 + "/OBJBLOCK/VARIABLE_DEF"
95 + "[./IDENT[@text='a']]/ASSIGN/EXPR"
96 + "/NUM_LONG[@text='0X10L']"
97 );
98
99 runVerifications(config, fileProcess, expected, expectedXpathQueries);
100 }
101
102 @Test
103 public void testFloatLiteralInfixAndSuffix() throws Exception {
104 final File fileProcess =
105 new File(getPath("InputXpathNumericalPrefixesInfixesSuffixesCharacterCaseThree.java"));
106 final DefaultConfiguration config =
107 createModuleConfig(NumericalPrefixesInfixesSuffixesCharacterCaseCheck.class);
108
109 final String[] expected = {
110 "4:15: " + getCheckMessage(
111 NumericalPrefixesInfixesSuffixesCharacterCaseCheck.class,
112 NumericalPrefixesInfixesSuffixesCharacterCaseCheck.MSG_INFIX),
113 };
114
115 final List<String> expectedXpathQueries = Arrays.asList(
116 "/COMPILATION_UNIT/CLASS_DEF"
117 + "[./IDENT[@text='InputXpathNumericalPrefixesInfixesSuffixesCharacterCaseThree']]"
118 + "/OBJBLOCK/VARIABLE_DEF"
119 + "[./IDENT[@text='a']]/ASSIGN/EXPR"
120 + "[./NUM_FLOAT[@text='1.2E3F']]",
121
122 "/COMPILATION_UNIT/CLASS_DEF"
123 + "[./IDENT[@text='InputXpathNumericalPrefixesInfixesSuffixesCharacterCaseThree']]"
124 + "/OBJBLOCK/VARIABLE_DEF"
125 + "[./IDENT[@text='a']]/ASSIGN/EXPR"
126 + "/NUM_FLOAT[@text='1.2E3F']"
127 );
128
129 runVerifications(config, fileProcess, expected, expectedXpathQueries);
130 }
131
132 @Test
133 public void testDoubleLiteralSuffix() throws Exception {
134 final File fileProcess =
135 new File(getPath("InputXpathNumericalPrefixesInfixesSuffixesCharacterCaseFour.java"));
136 final DefaultConfiguration config =
137 createModuleConfig(NumericalPrefixesInfixesSuffixesCharacterCaseCheck.class);
138
139 final String[] expected = {
140 "4:16: " + getCheckMessage(
141 NumericalPrefixesInfixesSuffixesCharacterCaseCheck.class,
142 NumericalPrefixesInfixesSuffixesCharacterCaseCheck.MSG_SUFFIX),
143 };
144
145 final List<String> expectedXpathQueries = Arrays.asList(
146 "/COMPILATION_UNIT/CLASS_DEF"
147 + "[./IDENT[@text='InputXpathNumericalPrefixesInfixesSuffixesCharacterCaseFour']]"
148 + "/OBJBLOCK/VARIABLE_DEF"
149 + "[./IDENT[@text='a']]/ASSIGN/EXPR"
150 + "[./NUM_DOUBLE[@text='10D']]",
151
152 "/COMPILATION_UNIT/CLASS_DEF"
153 + "[./IDENT[@text='InputXpathNumericalPrefixesInfixesSuffixesCharacterCaseFour']]"
154 + "/OBJBLOCK/VARIABLE_DEF"
155 + "[./IDENT[@text='a']]/ASSIGN/EXPR"
156 + "/NUM_DOUBLE[@text='10D']"
157 );
158
159 runVerifications(config, fileProcess, expected, expectedXpathQueries);
160 }
161 }