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.naming;
21
22 import static com.puppycrawl.tools.checkstyle.checks.naming.AbstractNameCheck.MSG_INVALID_PATTERN;
23
24 import org.junit.jupiter.api.Test;
25
26 import com.puppycrawl.tools.checkstyle.AbstractExamplesModuleTestSupport;
27
28 public class IllegalIdentifierNameCheckExamplesTest extends AbstractExamplesModuleTestSupport {
29 @Override
30 protected String getPackageLocation() {
31 return "com/puppycrawl/tools/checkstyle/checks/naming/illegalidentifiername";
32 }
33
34 @Test
35 public void testExample1() throws Exception {
36 final String format = "^(?!var$|\\S*\\$)\\S+$";
37
38 final String[] expected = {
39 "17:11: " + getCheckMessage(MSG_INVALID_PATTERN, "var", format),
40 "21:10: " + getCheckMessage(MSG_INVALID_PATTERN, "test$stuff", format),
41 };
42
43 verifyWithInlineConfigParser(getNonCompilablePath("Example1.java"), expected);
44 }
45
46 @Test
47 public void testExample2() throws Exception {
48 final String format =
49 "(?i)^(?!(when|record|yield|var|permits|sealed|open|transitive|_)$|(.*\\$)).+$";
50
51 final String[] expected = {
52 "17:11: " + getCheckMessage(MSG_INVALID_PATTERN, "var", format),
53 "18:7: " + getCheckMessage(MSG_INVALID_PATTERN, "record", format),
54 "19:10: " + getCheckMessage(MSG_INVALID_PATTERN, "yield", format),
55 "21:10: " + getCheckMessage(MSG_INVALID_PATTERN, "test$stuff", format),
56 "22:10: " + getCheckMessage(MSG_INVALID_PATTERN, "when", format),
57 "23:10: " + getCheckMessage(MSG_INVALID_PATTERN, "Record", format),
58 "25:19: " + getCheckMessage(MSG_INVALID_PATTERN, "record", format),
59 "33:7: " + getCheckMessage(MSG_INVALID_PATTERN, "open", format),
60 "34:10: " + getCheckMessage(MSG_INVALID_PATTERN, "transitive", format),
61 };
62
63 verifyWithInlineConfigParser(getNonCompilablePath("Example2.java"), expected);
64 }
65 }