1 24 package org.objectweb.speedo.tools; 25 26 import java.util.regex.Pattern ; 27 28 import junit.framework.TestCase; 29 30 35 public class TestStringReplace extends TestCase { 36 37 public TestStringReplace() { 38 this("TestStringReplace"); 39 } 40 public TestStringReplace(String name) { 41 super(name); 42 } 43 44 public static void main(String [] args) { 45 junit.textui.TestRunner.run(TestStringReplace.class); 46 } 47 48 public void testReplaceChar() { 49 assertEquals("org/objectweb/speedo/Foo", 50 StringReplace.replaceChar('.', '/', 51 "org.objectweb.speedo.Foo")); 52 assertEquals("org\\objectweb\\speedo\\Foo", 53 StringReplace.replaceChar('.', '\\', 54 "org.objectweb.speedo.Foo")); 55 } 56 57 public void testToJavaPattern() { 58 String s = "org.objectweb.s?peedo.*.*Foo*"; 59 assertEquals("org\\.objectweb\\.s.?peedo\\..*\\..*Foo.*", 60 StringReplace.toJavaPattern(s)); 61 } 62 public void testPatterns() { 63 assertPattern("org", "org", true); 64 assertPattern("org.objectweb.*", "org.objectweb.toto", true); 65 assertPattern("org.objectweb.*", "org.objectwe.toto", false); 66 assertPattern("org.objectweb.*#*", "org.objectweb.Toto#", true); 67 assertPattern("org.objectweb.*#*", "org.objectweb.Toto#f2", true); 68 assertPattern("org.objectweb.*#*", "org.objectwe.Toto#", false); 69 assertPattern("org.objectweb.*#f1", "org.objectweb.Toto#f1", true); 70 assertPattern("org.objectweb.*#f1", "org.objectweb.dgf.sdfsgdf.Toto#f1", true); 71 assertPattern("org.objectweb.*#f1", "org.objectweb.#f1", true); 72 assertPattern("org.objectweb.*#f1", "org.objectweb.Toto#f1", true); 73 assertPattern("org.objectweb.*#f1", "org.objectweb.Toto#f2", false); 74 assertPattern("org.objectweb.*#f?", "org.objectweb.Toto#f2", true); 75 assertPattern("org.objectweb.*#f?", "org.objectweb.Toto#f3", true); 76 77 } 78 79 private void assertPattern(String pattern, String exp, boolean match) { 80 assertEquals(match, 81 Pattern.compile(StringReplace.toJavaPattern(pattern)) 82 .matcher(exp).matches()); 83 } 84 } 85 | Popular Tags |