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;
20:
21: /**
22: * class to look at how we expand properties
23: */
24: public class PropertyExpansionTest extends BuildFileTest {
25:
26: public PropertyExpansionTest(String name) {
27: super (name);
28: }
29:
30: /**
31: * we bind to an existing test file because we are too lazy to write our
32: * own, and we don't really care what it is
33: */
34: public void setUp() {
35: configureProject("src/etc/testcases/core/immutable.xml");
36: }
37:
38: /**
39: * run through the test cases of expansion
40: */
41: public void testPropertyExpansion() {
42: assertExpandsTo("", "");
43: assertExpandsTo("$", "$");
44: assertExpandsTo("$$-", "$-");
45: assertExpandsTo("$$", "$");
46: project.setProperty("expanded", "EXPANDED");
47: assertExpandsTo("a${expanded}b", "aEXPANDEDb");
48: assertExpandsTo("${expanded}${expanded}", "EXPANDEDEXPANDED");
49: assertExpandsTo("$$$", "$$");
50: assertExpandsTo("$$$$-", "$$-");
51: assertExpandsTo("", "");
52: assertExpandsTo("Class$$subclass", "Class$subclass");
53: }
54:
55: /**
56: * new things we want
57: */
58: public void testDollarPassthru() {
59: assertExpandsTo("$-", "$-");
60: assertExpandsTo("Class$subclass", "Class$subclass");
61: assertExpandsTo("$$$-", "$$-");
62: assertExpandsTo("$$$$$", "$$$");
63: assertExpandsTo("${unassigned.property}",
64: "${unassigned.property}");
65: assertExpandsTo("a$b", "a$b");
66: assertExpandsTo("$}}", "$}}");
67: }
68:
69: /**
70: * old things we dont want; not a test no more
71: */
72: public void oldtestQuirkyLegacyBehavior() {
73: assertExpandsTo("Class$subclass", "Classsubclass");
74: assertExpandsTo("$$$-", "$-");
75: assertExpandsTo("a$b", "ab");
76: assertExpandsTo("$}}", "}}");
77: }
78:
79: /**
80: * little helper method to validate stuff
81: */
82: private void assertExpandsTo(String source, String expected) {
83: String actual = project.replaceProperties(source);
84: assertEquals(source, expected, actual);
85: }
86:
87: //end class
88: }
|