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 3.1 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. import org.junit.Before;
  20. import org.junit.Ignore;
  21. import org.junit.Rule;
  22. import org.junit.Test;
  23. import static org.junit.Assert.assertEquals;
  24. /**
  25. * class to look at how we expand properties
  26. */
  27. public class PropertyExpansionTest {
  28. @Rule
  29. public BuildFileRule buildRule = new BuildFileRule();
  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. @Before
  35. public void setUp() {
  36. buildRule.configureProject("src/etc/testcases/core/immutable.xml");
  37. }
  38. /**
  39. * run through the test cases of expansion
  40. */
  41. @Test
  42. public void testPropertyExpansion() {
  43. assertExpandsTo("","");
  44. assertExpandsTo("$","$");
  45. assertExpandsTo("$$-","$-");
  46. assertExpandsTo("$$","$");
  47. buildRule.getProject().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. * new things we want
  57. */
  58. @Test
  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. * old things we dont want; not a test no more
  70. */
  71. @Test
  72. @Ignore("Previously disabled through naming convention")
  73. public void oldtestQuirkyLegacyBehavior() {
  74. assertExpandsTo("Class$subclass","Classsubclass");
  75. assertExpandsTo("$$$-","$-");
  76. assertExpandsTo("a$b","ab");
  77. assertExpandsTo("$}}","}}");
  78. }
  79. /**
  80. * little helper method to validate stuff
  81. */
  82. private void assertExpandsTo(String source,String expected) {
  83. String actual = buildRule.getProject().replaceProperties(source);
  84. assertEquals(source,expected,actual);
  85. }
  86. //end class
  87. }