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