KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > util > regexp > RegexpTest


1 /*
2  * Copyright 2001,2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  *
16  */

17
18 package org.apache.tools.ant.util.regexp;
19
20 /**
21  * Tests for all implementations of the Regexp interface.
22  *
23  */

24 public abstract class RegexpTest extends RegexpMatcherTest {
25
26     private static final String JavaDoc test = "abcdefg-abcdefg";
27     private static final String JavaDoc pattern = "ab([^d]*)d([^f]*)f";
28
29     public RegexpTest(String JavaDoc 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