1 19 20 package org.netbeans.core.output2; 21 22 import java.util.regex.Matcher ; 23 import java.util.regex.Pattern ; 24 import junit.framework.*; 25 26 30 public class AbstractLinesTest extends TestCase { 31 32 public AbstractLinesTest(String testName) { 33 super(testName); 34 } 35 36 public void testEscapePattern() throws Exception { 37 doTestSingle("[", "hello[world", "helloworld]"); 38 doTestSingle("[a-z]", "hello[a-z]world", "helloworld"); 39 doTestSingle("(abc*ef)", "xx(abc*ef)xx", "abcdef"); 40 doTestSingle("(abc*ef", "xx(abc*efxx", "abcdef"); 41 doTestSingle("^abc", "xx(^abc*efxx", "abcdef"); 42 doTestSingle("\\d", "xx\\defxx", "8475"); 43 } 44 45 private void doTestSingle(String find, String success, String failure) { 46 Pattern patt = AbstractLines.escapePattern(find); 47 assertTrue(patt.matcher(success).find()); 48 assertFalse(patt.matcher(failure).find()); 49 } 50 51 } 52 | Popular Tags |