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.coding;
21
22 import static com.puppycrawl.tools.checkstyle.checks.coding.IllegalTokenCheck.MSG_KEY;
23
24 import org.junit.jupiter.api.Test;
25
26 import com.puppycrawl.tools.checkstyle.AbstractModuleTestSupport;
27
28 public class IllegalTokenCheckTest
29 extends AbstractModuleTestSupport {
30
31 @Override
32 protected String getPackageLocation() {
33 return "com/puppycrawl/tools/checkstyle/checks/coding/illegaltoken";
34 }
35
36 @Test
37 public void testIllegalTokensCheckDefaultTokenLabel() throws Exception {
38 final String[] expected = {
39 "36:14: " + getCheckMessage(MSG_KEY, "label:"),
40 "38:25: " + getCheckMessage(MSG_KEY, "anotherLabel:"),
41 };
42 verifyWithInlineConfigParser(
43 getPath("InputIllegalTokensCheckDefaultTokenLabel.java"), expected);
44 }
45
46 @Test
47 public void testIllegalTokensCheckSwitchAndPostIncDec() throws Exception {
48 final String[] expected = {
49 "18:9: " + getCheckMessage(MSG_KEY, "switch"),
50 "21:18: " + getCheckMessage(MSG_KEY, "--"),
51 "22:18: " + getCheckMessage(MSG_KEY, "++"),
52 };
53 verifyWithInlineConfigParser(
54 getPath("InputIllegalTokensCheckSwitchAndPostIncDec.java"), expected);
55 }
56
57 @Test
58 public void testIllegalTokensCheckTokenNative() throws Exception {
59 final String[] expected = {
60 "27:12: " + getCheckMessage(MSG_KEY, "native"),
61 };
62 verifyWithInlineConfigParser(
63 getPath("InputIllegalTokensCheckTokenNative.java"), expected);
64 }
65
66 @Test
67 public void testIllegalTokensCheckCommentsContent() throws Exception {
68
69 final String path = getPath("InputIllegalTokensCheckCommentsContent.java");
70 final String[] expected = {
71 "1:3: " + getCheckMessage(MSG_KEY,
72 "\\nIllegalToken\\ntokens = COMMENT_CONTENT\\n\\n\\n"),
73 "10:3: " + getCheckMessage(MSG_KEY,
74 "*\\n * // violation 10"
75 + " lines above 'is not allowed'\\n"
76 + " * // violation 2 lines above 'is not allowed'\\n"
77 + " * Test for illegal tokens\\n "),
78 "40:29: " + getCheckMessage(MSG_KEY,
79 " some comment href // violation, 'is not allowed'\\n"),
80 "44:28: " + getCheckMessage(MSG_KEY,
81 " some a href // violation, 'is not allowed'\\n"),
82 };
83 verifyWithInlineConfigParser(path, expected);
84 }
85
86 @Test
87 public void testIllegalTokensCheckBlockCommentBegin() throws Exception {
88
89 final String[] expected = {
90 "1:1: " + getCheckMessage(MSG_KEY, "/*"),
91 "10:1: " + getCheckMessage(MSG_KEY, "/*"),
92 };
93 verifyWithInlineConfigParser(
94 getPath("InputIllegalTokensCheckBlockCommentBegin.java"), expected);
95 }
96
97 @Test
98 public void testIllegalTokensCheckBlockCommentEnd() throws Exception {
99
100 final String[] expected = {
101 "6:1: " + getCheckMessage(MSG_KEY, "*/"),
102 "12:2: " + getCheckMessage(MSG_KEY, "*/"),
103 };
104 verifyWithInlineConfigParser(
105 getPath("InputIllegalTokensCheckBlockCommentEnd.java"), expected);
106 }
107
108 @Test
109 public void testIllegalTokensCheckSingleLineComment() throws Exception {
110
111 final String[] expected = {
112 "38:27: " + getCheckMessage(MSG_KEY, "//"),
113 "42:26: " + getCheckMessage(MSG_KEY, "//"),
114 };
115 verifyWithInlineConfigParser(
116 getPath("InputIllegalTokensCheckSingleLineComment.java"), expected);
117 }
118
119 }