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