01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: *
17: */
18:
19: package org.apache.tools.ant.util.regexp;
20:
21: /**
22: * Tests for all implementations of the Regexp interface.
23: *
24: */
25: public abstract class RegexpTest extends RegexpMatcherTest {
26:
27: private static final String test = "abcdefg-abcdefg";
28: private static final String pattern = "ab([^d]*)d([^f]*)f";
29:
30: public RegexpTest(String name) {
31: super (name);
32: }
33:
34: public final RegexpMatcher getImplementation() {
35: return getRegexpImplementation();
36: }
37:
38: public abstract Regexp getRegexpImplementation();
39:
40: public void testSubstitution() {
41: Regexp reg = (Regexp) getReg();
42: reg.setPattern(pattern);
43: assertTrue(reg.matches(test));
44: assertEquals("abedcfg-abcdefg", reg.substitute(test,
45: "ab\\2d\\1f", Regexp.MATCH_DEFAULT));
46: }
47:
48: public void testReplaceFirstSubstitution() {
49: Regexp reg = (Regexp) getReg();
50: reg.setPattern(pattern);
51: assertTrue(reg.matches(test));
52: assertEquals("abedcfg-abcdefg", reg.substitute(test,
53: "ab\\2d\\1f", Regexp.REPLACE_FIRST));
54: }
55:
56: public void testReplaceAllSubstitution() {
57: Regexp reg = (Regexp) getReg();
58: reg.setPattern(pattern);
59: assertTrue(reg.matches(test));
60: assertEquals("abedcfg-abedcfg", reg.substitute(test,
61: "ab\\2d\\1f", Regexp.REPLACE_ALL));
62: }
63: }
|