You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

PropertyExpansionTest.java 2.8 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /*
  2. * Licensed to the Apache Software Foundation (ASF) under one or more
  3. * contributor license agreements. See the NOTICE file distributed with
  4. * this work for additional information regarding copyright ownership.
  5. * The ASF licenses this file to You under the Apache License, Version 2.0
  6. * (the "License"); you may not use this file except in compliance with
  7. * the License. You may obtain a copy of the License at
  8. *
  9. * 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. package org.apache.tools.ant;
  19. /**
  20. * class to look at how we expand properties
  21. */
  22. public class PropertyExpansionTest extends BuildFileTest {
  23. public PropertyExpansionTest(String name) {
  24. super(name);
  25. }
  26. /**
  27. * we bind to an existing test file because we are too lazy to write our
  28. * own, and we don't really care what it is
  29. */
  30. public void setUp() {
  31. configureProject("src/etc/testcases/core/immutable.xml");
  32. }
  33. /**
  34. * run through the test cases of expansion
  35. */
  36. public void testPropertyExpansion() {
  37. assertExpandsTo("","");
  38. assertExpandsTo("$","$");
  39. assertExpandsTo("$$-","$-");
  40. assertExpandsTo("$$","$");
  41. project.setProperty("expanded","EXPANDED");
  42. assertExpandsTo("a${expanded}b","aEXPANDEDb");
  43. assertExpandsTo("${expanded}${expanded}","EXPANDEDEXPANDED");
  44. assertExpandsTo("$$$","$$");
  45. assertExpandsTo("$$$$-","$$-");
  46. assertExpandsTo("","");
  47. assertExpandsTo("Class$$subclass","Class$subclass");
  48. }
  49. /**
  50. * new things we want
  51. */
  52. public void testDollarPassthru() {
  53. assertExpandsTo("$-","$-");
  54. assertExpandsTo("Class$subclass","Class$subclass");
  55. assertExpandsTo("$$$-","$$-");
  56. assertExpandsTo("$$$$$","$$$");
  57. assertExpandsTo("${unassigned.property}","${unassigned.property}");
  58. assertExpandsTo("a$b","a$b");
  59. assertExpandsTo("$}}","$}}");
  60. }
  61. /**
  62. * old things we dont want; not a test no more
  63. */
  64. public void oldtestQuirkyLegacyBehavior() {
  65. assertExpandsTo("Class$subclass","Classsubclass");
  66. assertExpandsTo("$$$-","$-");
  67. assertExpandsTo("a$b","ab");
  68. assertExpandsTo("$}}","}}");
  69. }
  70. /**
  71. * little helper method to validate stuff
  72. */
  73. private void assertExpandsTo(String source,String expected) {
  74. String actual=project.replaceProperties(source);
  75. assertEquals(source,expected,actual);
  76. }
  77. //end class
  78. }