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 PatternVariableNameCheckExamplesTest extends AbstractExamplesModuleTestSupport {
29
30 @Override
31 public String getPackageLocation() {
32 return "com/puppycrawl/tools/checkstyle/checks/naming/patternvariablename";
33 }
34
35 @Test
36 public void testExample1() throws Exception {
37
38 final String pattern = "^([a-z][a-zA-Z0-9]*|_)$";
39
40 final String[] expected = {
41 "15:30: " + getCheckMessage(MSG_INVALID_PATTERN, "STRING", pattern),
42 "18:31: " + getCheckMessage(MSG_INVALID_PATTERN, "num_1", pattern),
43 };
44
45 verifyWithInlineConfigParser(getPath("Example1.java"), expected);
46 }
47
48 @Test
49 public void testExample2() throws Exception {
50
51 final String pattern = "^[a-z](_?[a-zA-Z0-9]+)*$";
52
53 final String[] expected = {
54 "17:30: " + getCheckMessage(MSG_INVALID_PATTERN, "STRING", pattern),
55 };
56
57 verifyWithInlineConfigParser(getPath("Example2.java"), expected);
58 }
59
60 @Test
61 public void testUseCase1() throws Exception {
62
63 final String pattern = "^[a-z][_a-zA-Z0-9]{2,}$";
64
65 final String[] expected = {
66 "17:30: " + getCheckMessage(MSG_INVALID_PATTERN, "STRING", pattern),
67 "22:31: " + getCheckMessage(MSG_INVALID_PATTERN, "n", pattern),
68 };
69
70 verifyWithInlineConfigParser(getPath("UseCase1.java"), expected);
71 }
72
73 @Test
74 public void testUseCase2() throws Exception {
75
76 final String[] expected = {
77 "37:30: " + getCheckMessage(MSG_INVALID_PATTERN, "STRING", "^([a-z][a-zA-Z0-9]*|_)$"),
78 "40:31: " + getCheckMessage(MSG_INVALID_PATTERN, "num_1", "^([a-z][a-zA-Z0-9]*|_)$"),
79 };
80
81 verifyWithInlineConfigParser(getPath("UseCase2.java"), expected);
82 }
83
84 }
85