KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > puppycrawl > tools > checkstyle > checks > GenericIllegalRegexpCheckTest


1 package com.puppycrawl.tools.checkstyle.checks;
2
3 import com.puppycrawl.tools.checkstyle.BaseCheckTestCase;
4 import com.puppycrawl.tools.checkstyle.DefaultConfiguration;
5
6 public class GenericIllegalRegexpCheckTest
7     extends BaseCheckTestCase
8 {
9     private DefaultConfiguration mCheckConfig;
10
11     public void setUp()
12     {
13         mCheckConfig = createCheckConfig(GenericIllegalRegexpCheck.class);
14     }
15
16     public void testIt()
17             throws Exception JavaDoc
18     {
19         final String JavaDoc illegal = "System\\.(out)|(err)\\.print(ln)?\\(";
20         mCheckConfig.addAttribute("format", illegal);
21         final String JavaDoc[] expected = {
22             "69: Line matches the illegal pattern '" + illegal + "'."
23         };
24         verify(mCheckConfig, getPath("InputSemantic.java"), expected);
25     }
26
27     public void testMessageProperty()
28         throws Exception JavaDoc
29     {
30         final String JavaDoc illegal = "System\\.(out)|(err)\\.print(ln)?\\(";
31         final String JavaDoc message = "Bad line :(";
32         mCheckConfig.addAttribute("format", illegal);
33         mCheckConfig.addAttribute("message", message);
34         final String JavaDoc[] expected = {
35             "69: " + message,
36         };
37         verify(mCheckConfig, getPath("InputSemantic.java"), expected);
38     }
39
40     public void testIgnoreCaseTrue()
41             throws Exception JavaDoc
42     {
43         final String JavaDoc illegal = "SYSTEM\\.(OUT)|(ERR)\\.PRINT(LN)?\\(";
44         mCheckConfig.addAttribute("format", illegal);
45         mCheckConfig.addAttribute("ignoreCase", "true");
46         final String JavaDoc[] expected = {
47             "69: Line matches the illegal pattern '" + illegal + "'."
48         };
49         verify(mCheckConfig, getPath("InputSemantic.java"), expected);
50     }
51
52     public void testIgnoreCaseFalse()
53             throws Exception JavaDoc
54     {
55         final String JavaDoc illegal = "SYSTEM\\.(OUT)|(ERR)\\.PRINT(LN)?\\(";
56         mCheckConfig.addAttribute("format", illegal);
57         mCheckConfig.addAttribute("ignoreCase", "false");
58         final String JavaDoc[] expected = {};
59         verify(mCheckConfig, getPath("InputSemantic.java"), expected);
60     }
61
62     public void testIgnoreCommentsCppStyle()
63             throws Exception JavaDoc
64     {
65         // See if the comment is removed properly
66
final String JavaDoc illegal = "don't use trailing comments";
67         mCheckConfig.addAttribute("format", illegal);
68         mCheckConfig.addAttribute("ignoreComments", "true");
69         final String JavaDoc[] expected = {
70         };
71         verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
72     }
73
74     public void testIgnoreCommentsFalseCppStyle()
75             throws Exception JavaDoc
76     {
77         // See if the comment is removed properly
78
final String JavaDoc illegal = "don't use trailing comments";
79         mCheckConfig.addAttribute("format", illegal);
80         mCheckConfig.addAttribute("ignoreComments", "false");
81         final String JavaDoc[] expected = {
82             "2: Line matches the illegal pattern '" + illegal + "'."
83         };
84         verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
85     }
86
87     public void testIgnoreCommentsCStyle()
88             throws Exception JavaDoc
89     {
90         // See if the comment is removed properly
91
final String JavaDoc illegal = "c-style 1";
92         mCheckConfig.addAttribute("format", illegal);
93         mCheckConfig.addAttribute("ignoreComments", "true");
94         final String JavaDoc[] expected = {
95         };
96         verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
97     }
98
99     public void testIgnoreCommentsFalseCStyle()
100             throws Exception JavaDoc
101     {
102         final String JavaDoc illegal = "c-style 1";
103         mCheckConfig.addAttribute("format", illegal);
104         mCheckConfig.addAttribute("ignoreComments", "false");
105         final String JavaDoc[] expected = {
106             "17: Line matches the illegal pattern '" + illegal + "'."
107         };
108         verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
109     }
110
111     public void testIgnoreCommentsMultipleCStyle()
112             throws Exception JavaDoc
113     {
114         // See if a second comment on the same line is removed properly
115
final String JavaDoc illegal = "c-style 2";
116         mCheckConfig.addAttribute("format", illegal);
117         mCheckConfig.addAttribute("ignoreComments", "true");
118         final String JavaDoc[] expected = {
119         };
120         verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
121     }
122
123     public void testIgnoreCommentsMultiLine()
124             throws Exception JavaDoc
125     {
126         final String JavaDoc illegal = "Let's check multi-line comments";
127         mCheckConfig.addAttribute("format", illegal);
128         mCheckConfig.addAttribute("ignoreComments", "true");
129         final String JavaDoc[] expected = {
130         };
131         verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
132     }
133
134     public void testIgnoreCommentsInlineStart()
135             throws Exception JavaDoc
136     {
137         final String JavaDoc illegal = "long ms /";
138         mCheckConfig.addAttribute("format", illegal);
139         mCheckConfig.addAttribute("ignoreComments", "true");
140         final String JavaDoc[] expected = {
141         };
142         verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
143     }
144
145     public void testIgnoreCommentsInlineEnd()
146             throws Exception JavaDoc
147     {
148         final String JavaDoc illegal = "int z";
149         mCheckConfig.addAttribute("format", illegal);
150         mCheckConfig.addAttribute("ignoreComments", "true");
151         final String JavaDoc[] expected = {
152             "20: Line matches the illegal pattern '" + illegal + "'."
153         };
154         verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
155     }
156
157     public void testIgnoreCommentsInlineMiddle() throws Exception JavaDoc
158     {
159         final String JavaDoc illegal = "int y";
160         mCheckConfig.addAttribute("format", illegal);
161         mCheckConfig.addAttribute("ignoreComments", "true");
162         final String JavaDoc[] expected = {
163             "21: Line matches the illegal pattern '" + illegal + "'."
164         };
165         verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
166     }
167
168     public void testIgnoreCommentsNoSpaces()
169             throws Exception JavaDoc
170     {
171         // make sure the comment is not turned into spaces
172
final String JavaDoc illegal = "long ms ";
173         mCheckConfig.addAttribute("format", illegal);
174         mCheckConfig.addAttribute("ignoreComments", "true");
175         final String JavaDoc[] expected = {
176         };
177         verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
178     }
179
180     public void test1371588()
181             throws Exception JavaDoc
182     {
183         // StackOverflowError with trailing space and ignoreComments
184
final String JavaDoc illegal = "\\s+$";
185         mCheckConfig.addAttribute("format", illegal);
186         mCheckConfig.addAttribute("ignoreComments", "true");
187         final String JavaDoc[] expected = {
188         };
189         verify(mCheckConfig, getPath("InputTrailingComment.java"), expected);
190     }
191 }
192
Popular Tags