1 17 18 package org.apache.tools.ant.util.regexp; 19 20 24 public abstract class RegexpTest extends RegexpMatcherTest { 25 26 private static final String test = "abcdefg-abcdefg"; 27 private static final String pattern = "ab([^d]*)d([^f]*)f"; 28 29 public RegexpTest(String name) { 30 super(name); 31 } 32 33 public final RegexpMatcher getImplementation() { 34 return getRegexpImplementation(); 35 } 36 37 public abstract Regexp getRegexpImplementation(); 38 39 public void testSubstitution() { 40 Regexp reg = (Regexp) getReg(); 41 reg.setPattern(pattern); 42 assertTrue(reg.matches(test)); 43 assertEquals("abedcfg-abcdefg", reg.substitute(test, "ab\\2d\\1f", 44 Regexp.MATCH_DEFAULT)); 45 } 46 47 public void testReplaceFirstSubstitution() { 48 Regexp reg = (Regexp) getReg(); 49 reg.setPattern(pattern); 50 assertTrue(reg.matches(test)); 51 assertEquals("abedcfg-abcdefg", reg.substitute(test, "ab\\2d\\1f", 52 Regexp.REPLACE_FIRST)); 53 } 54 55 public void testReplaceAllSubstitution() { 56 Regexp reg = (Regexp) getReg(); 57 reg.setPattern(pattern); 58 assertTrue(reg.matches(test)); 59 assertEquals("abedcfg-abedcfg", reg.substitute(test, "ab\\2d\\1f", 60 Regexp.REPLACE_ALL)); 61 } 62 } 63 | Popular Tags |