01: package com.puppycrawl.tools.checkstyle;
02:
03: import com.puppycrawl.tools.checkstyle.api.Utils;
04: import junit.framework.TestCase;
05: import org.apache.commons.beanutils.ConversionException;
06: import java.util.regex.Pattern;
07:
08: public class UtilsTest extends TestCase {
09: /**
10: * Test Utils.countCharInString.
11: */
12: public void testLengthExpandedTabs() throws Exception {
13: String s1 = "\t";
14: assertEquals(8, Utils.lengthExpandedTabs(s1, s1.length(), 8));
15:
16: String s2 = " \t";
17: assertEquals(8, Utils.lengthExpandedTabs(s2, s2.length(), 8));
18:
19: String s3 = "\t\t";
20: assertEquals(16, Utils.lengthExpandedTabs(s3, s3.length(), 8));
21:
22: String s4 = " \t ";
23: assertEquals(9, Utils.lengthExpandedTabs(s4, s4.length(), 8));
24:
25: assertEquals(0, Utils.lengthMinusTrailingWhitespace(""));
26: assertEquals(0, Utils.lengthMinusTrailingWhitespace(" \t "));
27: assertEquals(3, Utils.lengthMinusTrailingWhitespace(" 23"));
28: assertEquals(3, Utils.lengthMinusTrailingWhitespace(" 23 \t "));
29:
30: final Pattern r1 = Utils.getPattern("a");
31: final Pattern r2 = Utils.getPattern("a");
32: assertEquals(r1, r2);
33: }
34:
35: public void testBadRegex() {
36: try {
37: Utils.createPattern("[");
38: fail("expected to get conversion exception");
39: } catch (ConversionException e) {
40: ; // what is expected
41: }
42: }
43:
44: }
|