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;
20:
21: import junit.framework.TestCase;
22:
23: /**
24: * Tests for org.apache.tools.ant.util;GlobPatternMapper.
25: *
26: */
27: public class GlobPatternMapperTest extends TestCase {
28:
29: public GlobPatternMapperTest(String name) {
30: super (name);
31: }
32:
33: public void testNoPatternAtAll() {
34: GlobPatternMapper m = new GlobPatternMapper();
35: m.setFrom("foobar");
36: m.setTo("baz");
37: assertNull("Shouldn\'t match foobar", m.mapFileName("plonk"));
38: String[] result = m.mapFileName("foobar");
39: assertNotNull("Should match foobar", result);
40: assertEquals("only one result for foobar", 1, result.length);
41: assertEquals("baz", result[0]);
42: }
43:
44: public void testPostfixOnly() {
45: GlobPatternMapper m = new GlobPatternMapper();
46: m.setFrom("*foo");
47: m.setTo("*plonk");
48: assertNull("Shouldn\'t match *foo", m.mapFileName("bar.baz"));
49: String[] result = m.mapFileName("bar.foo");
50: assertNotNull("Should match *.foo", result);
51: assertEquals("only one result for bar.foo", 1, result.length);
52: assertEquals("bar.plonk", result[0]);
53:
54: // Try a silly case
55: m.setTo("foo*");
56: result = m.mapFileName("bar.foo");
57: assertEquals("foobar.", result[0]);
58: }
59:
60: public void testPrefixOnly() {
61: GlobPatternMapper m = new GlobPatternMapper();
62: m.setFrom("foo*");
63: m.setTo("plonk*");
64: assertNull("Shouldn\'t match foo*", m.mapFileName("bar.baz"));
65: String[] result = m.mapFileName("foo.bar");
66: assertNotNull("Should match foo*", result);
67: assertEquals("only one result for foo.bar", 1, result.length);
68: assertEquals("plonk.bar", result[0]);
69:
70: // Try a silly case
71: m.setTo("*foo");
72: result = m.mapFileName("foo.bar");
73: assertEquals(".barfoo", result[0]);
74: }
75:
76: public void testPreAndPostfix() {
77: GlobPatternMapper m = new GlobPatternMapper();
78: m.setFrom("foo*bar");
79: m.setTo("plonk*pling");
80: assertNull("Shouldn\'t match foo*bar", m.mapFileName("bar.baz"));
81: String[] result = m.mapFileName("foo.bar");
82: assertNotNull("Should match foo*bar", result);
83: assertEquals("only one result for foo.bar", 1, result.length);
84: assertEquals("plonk.pling", result[0]);
85:
86: // and a little longer
87: result = m.mapFileName("foo.baz.bar");
88: assertNotNull("Should match foo*bar", result);
89: assertEquals("only one result for foo.baz.bar", 1,
90: result.length);
91: assertEquals("plonk.baz.pling", result[0]);
92:
93: // and a little shorter
94: result = m.mapFileName("foobar");
95: assertNotNull("Should match foo*bar", result);
96: assertEquals("only one result for foobar", 1, result.length);
97: assertEquals("plonkpling", result[0]);
98: }
99: }
|