1 package com.puppycrawl.tools.checkstyle; 2 3 import com.puppycrawl.tools.checkstyle.api.Utils; 4 import junit.framework.TestCase; 5 import org.apache.commons.beanutils.ConversionException; 6 import java.util.regex.Pattern ; 7 8 public class UtilsTest 9 extends TestCase 10 { 11 14 public void testLengthExpandedTabs() 15 throws Exception 16 { 17 String s1 = "\t"; 18 assertEquals(8, Utils.lengthExpandedTabs(s1, s1.length(), 8)); 19 20 String s2 = " \t"; 21 assertEquals(8, Utils.lengthExpandedTabs(s2, s2.length(), 8)); 22 23 String s3 = "\t\t"; 24 assertEquals(16, Utils.lengthExpandedTabs(s3, s3.length(), 8)); 25 26 String s4 = " \t "; 27 assertEquals(9, Utils.lengthExpandedTabs(s4, s4.length(), 8)); 28 29 assertEquals(0, Utils.lengthMinusTrailingWhitespace("")); 30 assertEquals(0, Utils.lengthMinusTrailingWhitespace(" \t ")); 31 assertEquals(3, Utils.lengthMinusTrailingWhitespace(" 23")); 32 assertEquals(3, Utils.lengthMinusTrailingWhitespace(" 23 \t ")); 33 34 final Pattern r1 = Utils.getPattern("a"); 35 final Pattern r2 = Utils.getPattern("a"); 36 assertEquals(r1, r2); 37 } 38 39 public void testBadRegex() 40 { 41 try { 42 Utils.createPattern("["); 43 fail("expected to get conversion exception"); 44 } 45 catch (ConversionException e) { 46 ; } 48 } 49 50 } 51 | Popular Tags |