You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2017/12/01 15:49:30 UTC
[07/23] ant git commit: Normalise tabulation and line breaks (cf
master)
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/types/selectors/SignedSelectorTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/SignedSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/SignedSelectorTest.java
index 29da454..1eb40dc 100644
--- a/src/tests/junit/org/apache/tools/ant/types/selectors/SignedSelectorTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/SignedSelectorTest.java
@@ -1,54 +1,54 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types.selectors;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-/**
- * Testcase for the <signedselector> selector.
- *
- */
-public class SignedSelectorTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/types/selectors/signedselector.xml");
- }
-
- @Test
- public void testSelectSigned() {
- buildRule.executeTarget("selectsigned");
- }
-
- @Test
- public void testNotSelected() {
- buildRule.executeTarget("notselected");
- }
-
- @Test
- public void testName() {
- buildRule.executeTarget("name");
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types.selectors;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Testcase for the <signedselector> selector.
+ *
+ */
+public class SignedSelectorTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/types/selectors/signedselector.xml");
+ }
+
+ @Test
+ public void testSelectSigned() {
+ buildRule.executeTarget("selectsigned");
+ }
+
+ @Test
+ public void testNotSelected() {
+ buildRule.executeTarget("notselected");
+ }
+
+ @Test
+ public void testName() {
+ buildRule.executeTarget("name");
+ }
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/types/selectors/SizeSelectorTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/SizeSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/SizeSelectorTest.java
index 4cec0bd..37f41a5 100644
--- a/src/tests/junit/org/apache/tools/ant/types/selectors/SizeSelectorTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/SizeSelectorTest.java
@@ -1,237 +1,237 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types.selectors;
-
-import java.util.Locale;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.types.Parameter;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-/**
- * Tests Size Selectors
- *
- */
-public class SizeSelectorTest {
-
- @Rule
- public final BaseSelectorRule selectorRule = new BaseSelectorRule();
-
- /**
- * Test the code that validates the selector.
- */
- @Test
- public void testValidate() {
- SizeSelector s = new SizeSelector();
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("SizeSelector did not check for required fields");
- } catch (BuildException be1) {
- assertEquals("The value attribute is required, and must "
- + "be positive", be1.getMessage());
- }
-
- s = new SizeSelector();
- s.setValue(-10);
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("SizeSelector did not check for value being in the "
- + "allowable range");
- } catch (BuildException be2) {
- assertEquals("The value attribute is required, and must "
- + "be positive", be2.getMessage());
- }
-
- s = new SizeSelector();
- Parameter param = new Parameter();
- param.setName("garbage in");
- param.setValue("garbage out");
- Parameter[] params = {param};
- s.setParameters(params);
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("SizeSelector did not check for valid parameter element");
- } catch (BuildException be3) {
- assertEquals("Invalid parameter garbage in", be3.getMessage());
- }
-
- s = new SizeSelector();
- param = new Parameter();
- param.setName("value");
- param.setValue("garbage out");
- params[0] = param;
- s.setParameters(params);
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("SizeSelector accepted bad value as parameter");
- } catch (BuildException be4) {
- assertEquals("Invalid size setting garbage out",
- be4.getMessage());
- }
-
- s = new SizeSelector();
- Parameter param1 = new Parameter();
- Parameter param2 = new Parameter();
- param1.setName("value");
- param1.setValue("5");
- param2.setName("units");
- param2.setValue("garbage out");
- params = new Parameter[2];
- params[0] = param1;
- params[1] = param2;
- try {
- s.setParameters(params);
- s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("SizeSelector accepted bad units as parameter");
- } catch (BuildException be5) {
- assertEquals("garbage out is not a legal value for this attribute",
- be5.getMessage());
- }
-
- }
-
- /**
- * Tests to make sure that the selector is selecting files correctly.
- */
- @Test
- public void testSelectionBehaviour() {
- SizeSelector s;
- String results;
-
- SizeSelector.ByteUnits kilo = new SizeSelector.ByteUnits();
- kilo.setValue("K");
- SizeSelector.ByteUnits kibi = new SizeSelector.ByteUnits();
- kibi.setValue("Ki");
- SizeSelector.ByteUnits tibi = new SizeSelector.ByteUnits();
- tibi.setValue("Ti");
- SizeSelector.SizeComparisons less = new SizeSelector.SizeComparisons();
- less.setValue("less");
- SizeSelector.SizeComparisons equal = new SizeSelector.SizeComparisons();
- equal.setValue("equal");
- SizeSelector.SizeComparisons more = new SizeSelector.SizeComparisons();
- more.setValue("more");
-
-
-
- s = new SizeSelector();
- s.setValue(10);
- s.setWhen(less);
- results = selectorRule.selectionString(s);
- assertEquals("TFFFFFFFFFFT", results);
-
- s = new SizeSelector();
- s.setValue(10);
- s.setWhen(more);
- results = selectorRule.selectionString(s);
- assertEquals("TTTTTTTTTTTT", results);
-
- s = new SizeSelector();
- s.setValue(32);
- s.setWhen(equal);
- results = selectorRule.selectionString(s);
- assertEquals("TFFFTFFFFFFT", results);
-
- s = new SizeSelector();
- s.setValue(7);
- s.setWhen(more);
- s.setUnits(kilo);
- results = selectorRule.selectionString(s);
- assertEquals("TFTFFTTTTTTT", results);
-
- s = new SizeSelector();
- s.setValue(7);
- s.setWhen(more);
- s.setUnits(kibi);
- results = selectorRule.selectionString(s);
- assertEquals("TFTFFFTTFTTT", results);
-
- s = new SizeSelector();
- s.setValue(99999);
- s.setWhen(more);
- s.setUnits(tibi);
- results = selectorRule.selectionString(s);
- assertEquals("TFFFFFFFFFFT", results);
-
- s = new SizeSelector();
- Parameter param1 = new Parameter();
- Parameter param2 = new Parameter();
- Parameter param3 = new Parameter();
- param1.setName("value");
- param1.setValue("20");
- param2.setName("units");
- param2.setValue("Ki");
- param3.setName("when");
- param3.setValue("more");
- Parameter[] params = {param1,param2,param3};
- s.setParameters(params);
- results = selectorRule.selectionString(s);
- assertEquals("TFFFFFFTFFTT", results);
-
-
- }
-
- @Test
- public void testParameterParsingLowerCase() {
- testCaseInsensitiveParameterParsing("units");
- }
-
- @Test
- public void testParameterParsingUpperCase() {
- testCaseInsensitiveParameterParsing("UNITS");
- }
-
- @Test
- public void testParameterParsingLowerCaseTurkish() {
- Locale l = Locale.getDefault();
- try {
- Locale.setDefault(new Locale("tr"));
- testCaseInsensitiveParameterParsing("units");
- } finally {
- Locale.setDefault(l);
- }
- }
-
- @Test
- public void testParameterParsingUpperCaseTurkish() {
- Locale l = Locale.getDefault();
- try {
- Locale.setDefault(new Locale("tr"));
- testCaseInsensitiveParameterParsing("UNITS");
- } finally {
- Locale.setDefault(l);
- }
- }
-
- private void testCaseInsensitiveParameterParsing(String name) {
- SizeSelector s = new SizeSelector();
- Parameter p = new Parameter();
- p.setName(name);
- p.setValue("foo");
- try {
- s.setParameters(new Parameter[] {p});
- fail("should have caused an exception");
- } catch (BuildException be) {
- assertEquals("foo is not a legal value for this attribute",
- be.getMessage());
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types.selectors;
+
+import java.util.Locale;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.Parameter;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests Size Selectors
+ *
+ */
+public class SizeSelectorTest {
+
+ @Rule
+ public final BaseSelectorRule selectorRule = new BaseSelectorRule();
+
+ /**
+ * Test the code that validates the selector.
+ */
+ @Test
+ public void testValidate() {
+ SizeSelector s = new SizeSelector();
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("SizeSelector did not check for required fields");
+ } catch (BuildException be1) {
+ assertEquals("The value attribute is required, and must "
+ + "be positive", be1.getMessage());
+ }
+
+ s = new SizeSelector();
+ s.setValue(-10);
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("SizeSelector did not check for value being in the "
+ + "allowable range");
+ } catch (BuildException be2) {
+ assertEquals("The value attribute is required, and must "
+ + "be positive", be2.getMessage());
+ }
+
+ s = new SizeSelector();
+ Parameter param = new Parameter();
+ param.setName("garbage in");
+ param.setValue("garbage out");
+ Parameter[] params = {param};
+ s.setParameters(params);
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("SizeSelector did not check for valid parameter element");
+ } catch (BuildException be3) {
+ assertEquals("Invalid parameter garbage in", be3.getMessage());
+ }
+
+ s = new SizeSelector();
+ param = new Parameter();
+ param.setName("value");
+ param.setValue("garbage out");
+ params[0] = param;
+ s.setParameters(params);
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("SizeSelector accepted bad value as parameter");
+ } catch (BuildException be4) {
+ assertEquals("Invalid size setting garbage out",
+ be4.getMessage());
+ }
+
+ s = new SizeSelector();
+ Parameter param1 = new Parameter();
+ Parameter param2 = new Parameter();
+ param1.setName("value");
+ param1.setValue("5");
+ param2.setName("units");
+ param2.setValue("garbage out");
+ params = new Parameter[2];
+ params[0] = param1;
+ params[1] = param2;
+ try {
+ s.setParameters(params);
+ s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("SizeSelector accepted bad units as parameter");
+ } catch (BuildException be5) {
+ assertEquals("garbage out is not a legal value for this attribute",
+ be5.getMessage());
+ }
+
+ }
+
+ /**
+ * Tests to make sure that the selector is selecting files correctly.
+ */
+ @Test
+ public void testSelectionBehaviour() {
+ SizeSelector s;
+ String results;
+
+ SizeSelector.ByteUnits kilo = new SizeSelector.ByteUnits();
+ kilo.setValue("K");
+ SizeSelector.ByteUnits kibi = new SizeSelector.ByteUnits();
+ kibi.setValue("Ki");
+ SizeSelector.ByteUnits tibi = new SizeSelector.ByteUnits();
+ tibi.setValue("Ti");
+ SizeSelector.SizeComparisons less = new SizeSelector.SizeComparisons();
+ less.setValue("less");
+ SizeSelector.SizeComparisons equal = new SizeSelector.SizeComparisons();
+ equal.setValue("equal");
+ SizeSelector.SizeComparisons more = new SizeSelector.SizeComparisons();
+ more.setValue("more");
+
+
+
+ s = new SizeSelector();
+ s.setValue(10);
+ s.setWhen(less);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFFFFFFFFT", results);
+
+ s = new SizeSelector();
+ s.setValue(10);
+ s.setWhen(more);
+ results = selectorRule.selectionString(s);
+ assertEquals("TTTTTTTTTTTT", results);
+
+ s = new SizeSelector();
+ s.setValue(32);
+ s.setWhen(equal);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFTFFFFFFT", results);
+
+ s = new SizeSelector();
+ s.setValue(7);
+ s.setWhen(more);
+ s.setUnits(kilo);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFTFFTTTTTTT", results);
+
+ s = new SizeSelector();
+ s.setValue(7);
+ s.setWhen(more);
+ s.setUnits(kibi);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFTFFFTTFTTT", results);
+
+ s = new SizeSelector();
+ s.setValue(99999);
+ s.setWhen(more);
+ s.setUnits(tibi);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFFFFFFFFT", results);
+
+ s = new SizeSelector();
+ Parameter param1 = new Parameter();
+ Parameter param2 = new Parameter();
+ Parameter param3 = new Parameter();
+ param1.setName("value");
+ param1.setValue("20");
+ param2.setName("units");
+ param2.setValue("Ki");
+ param3.setName("when");
+ param3.setValue("more");
+ Parameter[] params = {param1,param2,param3};
+ s.setParameters(params);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFFFFTFFTT", results);
+
+
+ }
+
+ @Test
+ public void testParameterParsingLowerCase() {
+ testCaseInsensitiveParameterParsing("units");
+ }
+
+ @Test
+ public void testParameterParsingUpperCase() {
+ testCaseInsensitiveParameterParsing("UNITS");
+ }
+
+ @Test
+ public void testParameterParsingLowerCaseTurkish() {
+ Locale l = Locale.getDefault();
+ try {
+ Locale.setDefault(new Locale("tr"));
+ testCaseInsensitiveParameterParsing("units");
+ } finally {
+ Locale.setDefault(l);
+ }
+ }
+
+ @Test
+ public void testParameterParsingUpperCaseTurkish() {
+ Locale l = Locale.getDefault();
+ try {
+ Locale.setDefault(new Locale("tr"));
+ testCaseInsensitiveParameterParsing("UNITS");
+ } finally {
+ Locale.setDefault(l);
+ }
+ }
+
+ private void testCaseInsensitiveParameterParsing(String name) {
+ SizeSelector s = new SizeSelector();
+ Parameter p = new Parameter();
+ p.setName(name);
+ p.setValue("foo");
+ try {
+ s.setParameters(new Parameter[] {p});
+ fail("should have caused an exception");
+ } catch (BuildException be) {
+ assertEquals("foo is not a legal value for this attribute",
+ be.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/types/selectors/TokenizedPatternTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/TokenizedPatternTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/TokenizedPatternTest.java
index 55f7b03..4e95c2c 100644
--- a/src/tests/junit/org/apache/tools/ant/types/selectors/TokenizedPatternTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/TokenizedPatternTest.java
@@ -1,77 +1,77 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types.selectors;
-
-import java.io.File;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-
-public class TokenizedPatternTest {
- private static final String DOT_SVN_PATTERN =
- SelectorUtils.DEEP_TREE_MATCH + File.separator + ".svn"
- + File.separator + SelectorUtils.DEEP_TREE_MATCH;
-
- @Test
- public void testTokenization() {
- TokenizedPattern pat = new TokenizedPattern(DOT_SVN_PATTERN);
- assertEquals(3, pat.depth());
- assertEquals(DOT_SVN_PATTERN, pat.getPattern());
- assertTrue(pat.containsPattern(SelectorUtils.DEEP_TREE_MATCH));
- assertTrue(pat.containsPattern(".svn"));
- }
-
- @Test
- public void testEndsWith() {
- assertTrue(new TokenizedPattern(DOT_SVN_PATTERN)
- .endsWith(SelectorUtils.DEEP_TREE_MATCH));
- }
-
- @Test
- public void testWithoutLastToken() {
- assertEquals(SelectorUtils.DEEP_TREE_MATCH + File.separatorChar
- + ".svn" + File.separator,
- new TokenizedPattern(DOT_SVN_PATTERN)
- .withoutLastToken().getPattern());
- }
-
- @Test
- public void testMatchPath() {
- File f = new File(".svn");
- TokenizedPath p = new TokenizedPath(f.getAbsolutePath());
- assertTrue(new TokenizedPattern(DOT_SVN_PATTERN).matchPath(p, true));
- assertTrue(new TokenizedPattern(DOT_SVN_PATTERN)
- .withoutLastToken().matchPath(p, true));
- }
-
- @Test
- /**
- * this test illustrates the behavior described in bugzilla 59114
- * meaning that the pattern "**" matches the empty path
- * but the pattern "*" does not
- */
- public void testEmptyFolderWithStarStar() {
- TokenizedPath p = TokenizedPath.EMPTY_PATH;
- assertTrue(new TokenizedPattern(SelectorUtils.DEEP_TREE_MATCH).matchPath(p, true));
- assertFalse(new TokenizedPattern("*").matchPath(p, true));
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types.selectors;
+
+import java.io.File;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class TokenizedPatternTest {
+ private static final String DOT_SVN_PATTERN =
+ SelectorUtils.DEEP_TREE_MATCH + File.separator + ".svn"
+ + File.separator + SelectorUtils.DEEP_TREE_MATCH;
+
+ @Test
+ public void testTokenization() {
+ TokenizedPattern pat = new TokenizedPattern(DOT_SVN_PATTERN);
+ assertEquals(3, pat.depth());
+ assertEquals(DOT_SVN_PATTERN, pat.getPattern());
+ assertTrue(pat.containsPattern(SelectorUtils.DEEP_TREE_MATCH));
+ assertTrue(pat.containsPattern(".svn"));
+ }
+
+ @Test
+ public void testEndsWith() {
+ assertTrue(new TokenizedPattern(DOT_SVN_PATTERN)
+ .endsWith(SelectorUtils.DEEP_TREE_MATCH));
+ }
+
+ @Test
+ public void testWithoutLastToken() {
+ assertEquals(SelectorUtils.DEEP_TREE_MATCH + File.separatorChar
+ + ".svn" + File.separator,
+ new TokenizedPattern(DOT_SVN_PATTERN)
+ .withoutLastToken().getPattern());
+ }
+
+ @Test
+ public void testMatchPath() {
+ File f = new File(".svn");
+ TokenizedPath p = new TokenizedPath(f.getAbsolutePath());
+ assertTrue(new TokenizedPattern(DOT_SVN_PATTERN).matchPath(p, true));
+ assertTrue(new TokenizedPattern(DOT_SVN_PATTERN)
+ .withoutLastToken().matchPath(p, true));
+ }
+
+ @Test
+ /**
+ * this test illustrates the behavior described in bugzilla 59114
+ * meaning that the pattern "**" matches the empty path
+ * but the pattern "*" does not
+ */
+ public void testEmptyFolderWithStarStar() {
+ TokenizedPath p = TokenizedPath.EMPTY_PATH;
+ assertTrue(new TokenizedPattern(SelectorUtils.DEEP_TREE_MATCH).matchPath(p, true));
+ assertFalse(new TokenizedPattern("*").matchPath(p, true));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/types/selectors/TypeSelectorTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/TypeSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/TypeSelectorTest.java
index 777d772..f775f59 100644
--- a/src/tests/junit/org/apache/tools/ant/types/selectors/TypeSelectorTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/TypeSelectorTest.java
@@ -1,81 +1,81 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types.selectors;
-
-import org.apache.tools.ant.BuildException;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-/**
- * Tests Type Selectors.
- *
- */
-public class TypeSelectorTest {
-
- @Rule
- public BaseSelectorRule selectorRule = new BaseSelectorRule();
-
-
- /**
- * Test the code that validates the selector.
- */
- @Test
- public void testValidate() {
- TypeSelector s = new TypeSelector();
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0] ,selectorRule.getFiles()[0]);
- fail("TypeSelector did not check for required fields");
- } catch (BuildException be1) {
- assertEquals("The type attribute is required"
- , be1.getMessage());
- }
- }
-
- /**
- * Tests to make sure that the selector is selecting files correctly.
- */
- @Test
- public void testSelectionBehaviour() {
- TypeSelector s;
- String results;
-
- TypeSelector.FileType directory = new TypeSelector.FileType();
- directory.setValue("dir");
- TypeSelector.FileType file = new TypeSelector.FileType();
- file.setValue("file");
-
-
-
- s = new TypeSelector();
- s.setType(directory);
- results = selectorRule.selectionString(s);
- assertEquals("TFFFFFFFFFFT", results);
-
- s = new TypeSelector();
- s.setType(file);
- results = selectorRule.selectionString(s);
- assertEquals("FTTTTTTTTTTF", results);
-
-
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types.selectors;
+
+import org.apache.tools.ant.BuildException;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests Type Selectors.
+ *
+ */
+public class TypeSelectorTest {
+
+ @Rule
+ public BaseSelectorRule selectorRule = new BaseSelectorRule();
+
+
+ /**
+ * Test the code that validates the selector.
+ */
+ @Test
+ public void testValidate() {
+ TypeSelector s = new TypeSelector();
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0] ,selectorRule.getFiles()[0]);
+ fail("TypeSelector did not check for required fields");
+ } catch (BuildException be1) {
+ assertEquals("The type attribute is required"
+ , be1.getMessage());
+ }
+ }
+
+ /**
+ * Tests to make sure that the selector is selecting files correctly.
+ */
+ @Test
+ public void testSelectionBehaviour() {
+ TypeSelector s;
+ String results;
+
+ TypeSelector.FileType directory = new TypeSelector.FileType();
+ directory.setValue("dir");
+ TypeSelector.FileType file = new TypeSelector.FileType();
+ file.setValue("file");
+
+
+
+ s = new TypeSelector();
+ s.setType(directory);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFFFFFFFFT", results);
+
+ s = new TypeSelector();
+ s.setType(file);
+ results = selectorRule.selectionString(s);
+ assertEquals("FTTTTTTTTTTF", results);
+
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java b/src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java
index 22a2739..48a4cbd 100644
--- a/src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/Base64ConverterTest.java
@@ -1,43 +1,43 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.util;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * TestCase for Base64Converter.
- *
- */
-public class Base64ConverterTest {
-
- @Test
- public void testOneValue() {
- byte[] mybytes = {0, 0, (byte)0xFF};
- Base64Converter base64Converter = new Base64Converter();
- assertEquals("AAD/",base64Converter.encode(mybytes));
- }
-
- @Test
- public void testHelloWorld() {
- byte[] mybytes = "Hello World".getBytes();
- Base64Converter base64Converter = new Base64Converter();
- assertEquals("SGVsbG8gV29ybGQ=", base64Converter.encode(mybytes));
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.util;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * TestCase for Base64Converter.
+ *
+ */
+public class Base64ConverterTest {
+
+ @Test
+ public void testOneValue() {
+ byte[] mybytes = {0, 0, (byte)0xFF};
+ Base64Converter base64Converter = new Base64Converter();
+ assertEquals("AAD/",base64Converter.encode(mybytes));
+ }
+
+ @Test
+ public void testHelloWorld() {
+ byte[] mybytes = "Hello World".getBytes();
+ Base64Converter base64Converter = new Base64Converter();
+ assertEquals("SGVsbG8gV29ybGQ=", base64Converter.encode(mybytes));
+ }
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/util/ClasspathUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/ClasspathUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/ClasspathUtilsTest.java
index 4399f91..3cffa10 100644
--- a/src/tests/junit/org/apache/tools/ant/util/ClasspathUtilsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/ClasspathUtilsTest.java
@@ -1,67 +1,67 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.util;
-
-import java.io.IOException;
-import java.util.Enumeration;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.types.Path;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-
-/**
- * Test case for ClasspathUtils
- *
- */
-public class ClasspathUtilsTest {
-
- private Project p;
-
- @Before
- public void setUp() {
- p = new Project();
- p.init();
- }
-
-
- @Test
- public void testOnlyOneInstance() {
- Enumeration enumeration;
- String list = "";
- ClassLoader c = ClasspathUtils.getUniqueClassLoaderForPath(p, (Path) null, false);
- try {
- enumeration = c.getResources(
- "org/apache/tools/ant/taskdefs/defaults.properties");
- } catch (IOException e) {
- throw new BuildException(
- "Could not get the defaults.properties resource", e);
- }
- int count = 0;
- while (enumeration.hasMoreElements()) {
- list = list + " " + enumeration.nextElement();
- count++;
- }
- assertTrue("Should be only one and not " + count + " " + list, count == 1);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.util;
+
+import java.io.IOException;
+import java.util.Enumeration;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.Path;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+
+/**
+ * Test case for ClasspathUtils
+ *
+ */
+public class ClasspathUtilsTest {
+
+ private Project p;
+
+ @Before
+ public void setUp() {
+ p = new Project();
+ p.init();
+ }
+
+
+ @Test
+ public void testOnlyOneInstance() {
+ Enumeration enumeration;
+ String list = "";
+ ClassLoader c = ClasspathUtils.getUniqueClassLoaderForPath(p, (Path) null, false);
+ try {
+ enumeration = c.getResources(
+ "org/apache/tools/ant/taskdefs/defaults.properties");
+ } catch (IOException e) {
+ throw new BuildException(
+ "Could not get the defaults.properties resource", e);
+ }
+ int count = 0;
+ while (enumeration.hasMoreElements()) {
+ list = list + " " + enumeration.nextElement();
+ count++;
+ }
+ assertTrue("Should be only one and not " + count + " " + list, count == 1);
+ }
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/util/CollectionUtilsTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/CollectionUtilsTest.java b/src/tests/junit/org/apache/tools/ant/util/CollectionUtilsTest.java
index 5bcbc12..425dc47 100644
--- a/src/tests/junit/org/apache/tools/ant/util/CollectionUtilsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/CollectionUtilsTest.java
@@ -1,102 +1,102 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.util;
-
-import java.util.Hashtable;
-import java.util.Properties;
-import java.util.Stack;
-import java.util.Vector;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-/**
- * Tests for org.apache.tools.ant.util.CollectionUtils.
- *
- */
-public class CollectionUtilsTest {
-
-
- @Test
- public void testVectorEquals() {
- assertTrue(!CollectionUtils.equals(null, new Vector()));
- assertTrue(!CollectionUtils.equals(new Vector(), null));
- assertTrue(CollectionUtils.equals(new Vector(), new Vector()));
- Vector v1 = new Vector();
- Stack s2 = new Stack();
- v1.addElement("foo");
- s2.push("foo");
- assertTrue(CollectionUtils.equals(v1, s2));
- assertTrue(CollectionUtils.equals(s2, v1));
- v1.addElement("bar");
- assertTrue(!CollectionUtils.equals(v1, s2));
- assertTrue(!CollectionUtils.equals(s2, v1));
- s2.push("bar");
- assertTrue(CollectionUtils.equals(v1, s2));
- assertTrue(CollectionUtils.equals(s2, v1));
- s2.push("baz");
- assertTrue(!CollectionUtils.equals(v1, s2));
- assertTrue(!CollectionUtils.equals(s2, v1));
- v1.addElement("baz");
- assertTrue(CollectionUtils.equals(v1, s2));
- assertTrue(CollectionUtils.equals(s2, v1));
- v1.addElement("zyzzy");
- s2.push("zyzzy2");
- assertTrue(!CollectionUtils.equals(v1, s2));
- assertTrue(!CollectionUtils.equals(s2, v1));
- }
-
- @Test
- public void testDictionaryEquals() {
- assertTrue(!CollectionUtils.equals(null, new Hashtable()));
- assertTrue(!CollectionUtils.equals(new Hashtable(), null));
- assertTrue(CollectionUtils.equals(new Hashtable(), new Properties()));
- Hashtable h1 = new Hashtable();
- Properties p2 = new Properties();
- h1.put("foo", "");
- p2.put("foo", "");
- assertTrue(CollectionUtils.equals(h1, p2));
- assertTrue(CollectionUtils.equals(p2, h1));
- h1.put("bar", "");
- assertTrue(!CollectionUtils.equals(h1, p2));
- assertTrue(!CollectionUtils.equals(p2, h1));
- p2.put("bar", "");
- assertTrue(CollectionUtils.equals(h1, p2));
- assertTrue(CollectionUtils.equals(p2, h1));
- p2.put("baz", "");
- assertTrue(!CollectionUtils.equals(h1, p2));
- assertTrue(!CollectionUtils.equals(p2, h1));
- h1.put("baz", "");
- assertTrue(CollectionUtils.equals(h1, p2));
- assertTrue(CollectionUtils.equals(p2, h1));
- h1.put("zyzzy", "");
- p2.put("zyzzy2", "");
- assertTrue(!CollectionUtils.equals(h1, p2));
- assertTrue(!CollectionUtils.equals(p2, h1));
- p2.put("zyzzy", "");
- h1.put("zyzzy2", "");
- assertTrue(CollectionUtils.equals(h1, p2));
- assertTrue(CollectionUtils.equals(p2, h1));
- h1.put("dada", "1");
- p2.put("dada", "2");
- assertTrue(!CollectionUtils.equals(h1, p2));
- assertTrue(!CollectionUtils.equals(p2, h1));
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.util;
+
+import java.util.Hashtable;
+import java.util.Properties;
+import java.util.Stack;
+import java.util.Vector;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for org.apache.tools.ant.util.CollectionUtils.
+ *
+ */
+public class CollectionUtilsTest {
+
+
+ @Test
+ public void testVectorEquals() {
+ assertTrue(!CollectionUtils.equals(null, new Vector()));
+ assertTrue(!CollectionUtils.equals(new Vector(), null));
+ assertTrue(CollectionUtils.equals(new Vector(), new Vector()));
+ Vector v1 = new Vector();
+ Stack s2 = new Stack();
+ v1.addElement("foo");
+ s2.push("foo");
+ assertTrue(CollectionUtils.equals(v1, s2));
+ assertTrue(CollectionUtils.equals(s2, v1));
+ v1.addElement("bar");
+ assertTrue(!CollectionUtils.equals(v1, s2));
+ assertTrue(!CollectionUtils.equals(s2, v1));
+ s2.push("bar");
+ assertTrue(CollectionUtils.equals(v1, s2));
+ assertTrue(CollectionUtils.equals(s2, v1));
+ s2.push("baz");
+ assertTrue(!CollectionUtils.equals(v1, s2));
+ assertTrue(!CollectionUtils.equals(s2, v1));
+ v1.addElement("baz");
+ assertTrue(CollectionUtils.equals(v1, s2));
+ assertTrue(CollectionUtils.equals(s2, v1));
+ v1.addElement("zyzzy");
+ s2.push("zyzzy2");
+ assertTrue(!CollectionUtils.equals(v1, s2));
+ assertTrue(!CollectionUtils.equals(s2, v1));
+ }
+
+ @Test
+ public void testDictionaryEquals() {
+ assertTrue(!CollectionUtils.equals(null, new Hashtable()));
+ assertTrue(!CollectionUtils.equals(new Hashtable(), null));
+ assertTrue(CollectionUtils.equals(new Hashtable(), new Properties()));
+ Hashtable h1 = new Hashtable();
+ Properties p2 = new Properties();
+ h1.put("foo", "");
+ p2.put("foo", "");
+ assertTrue(CollectionUtils.equals(h1, p2));
+ assertTrue(CollectionUtils.equals(p2, h1));
+ h1.put("bar", "");
+ assertTrue(!CollectionUtils.equals(h1, p2));
+ assertTrue(!CollectionUtils.equals(p2, h1));
+ p2.put("bar", "");
+ assertTrue(CollectionUtils.equals(h1, p2));
+ assertTrue(CollectionUtils.equals(p2, h1));
+ p2.put("baz", "");
+ assertTrue(!CollectionUtils.equals(h1, p2));
+ assertTrue(!CollectionUtils.equals(p2, h1));
+ h1.put("baz", "");
+ assertTrue(CollectionUtils.equals(h1, p2));
+ assertTrue(CollectionUtils.equals(p2, h1));
+ h1.put("zyzzy", "");
+ p2.put("zyzzy2", "");
+ assertTrue(!CollectionUtils.equals(h1, p2));
+ assertTrue(!CollectionUtils.equals(p2, h1));
+ p2.put("zyzzy", "");
+ h1.put("zyzzy2", "");
+ assertTrue(CollectionUtils.equals(h1, p2));
+ assertTrue(CollectionUtils.equals(p2, h1));
+ h1.put("dada", "1");
+ p2.put("dada", "2");
+ assertTrue(!CollectionUtils.equals(h1, p2));
+ assertTrue(!CollectionUtils.equals(p2, h1));
+ }
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java b/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java
index 80a8d6b..fe09ce9 100644
--- a/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/DOMElementWriterTest.java
@@ -1,305 +1,305 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.util;
-
-import org.junit.Test;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-
-import java.io.IOException;
-import java.io.StringWriter;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-/**
- * Tests for org.apache.tools.ant.util.DOMElementWriter.
- *
- */
-public class DOMElementWriterTest {
-
- private DOMElementWriter w = new DOMElementWriter();
-
- @Test
- public void testIsReference() {
- assertTrue("", w.isReference(""));
- assertTrue(" ", w.isReference(" "));
- assertTrue(" ", w.isReference(" "));
- assertTrue("&#A0;", !w.isReference("&#A0;"));
- assertTrue("20;", !w.isReference("20;"));
- assertTrue("", !w.isReference(""));
- assertTrue(""", w.isReference("""));
- assertTrue("'", w.isReference("'"));
- assertTrue(">", w.isReference(">"));
- assertTrue("<", w.isReference("<"));
- assertTrue("&", w.isReference("&"));
- }
-
- @Test
- public void testEncode() {
- assertEquals("&#20;", w.encode(""));
- assertEquals("&#x20;", w.encode(" "));
- assertEquals("&#xA0;", w.encode(" "));
- assertEquals("&#A0;", w.encode("&#A0;"));
- assertEquals("20;", w.encode("20;"));
- assertEquals("&#20", w.encode(""));
- assertEquals("&quot;", w.encode("""));
- assertEquals("&apos;", w.encode("'"));
- assertEquals("&gt;", w.encode(">"));
- assertEquals("&lt;", w.encode("<"));
- assertEquals("&amp;", w.encode("&"));
- assertEquals(""", w.encode("\""));
- assertEquals("<", w.encode("<"));
- assertEquals("&", w.encode("&"));
- assertEquals("", w.encode("\u0017"));
- assertEquals("\r\n\t", w.encode("\r\n\t"));
- }
-
- @Test
- public void testEncodeAttributeValue() {
- assertEquals("&#20;", w.encodeAttributeValue(""));
- assertEquals("&#x20;", w.encodeAttributeValue(" "));
- assertEquals("&#xA0;", w.encodeAttributeValue(" "));
- assertEquals("&#A0;", w.encodeAttributeValue("&#A0;"));
- assertEquals("20;", w.encodeAttributeValue("20;"));
- assertEquals("&#20", w.encodeAttributeValue(""));
- assertEquals("&quot;", w.encodeAttributeValue("""));
- assertEquals("&apos;", w.encodeAttributeValue("'"));
- assertEquals("&gt;", w.encodeAttributeValue(">"));
- assertEquals("&lt;", w.encodeAttributeValue("<"));
- assertEquals("&amp;", w.encodeAttributeValue("&"));
- assertEquals(""", w.encodeAttributeValue("\""));
- assertEquals("<", w.encodeAttributeValue("<"));
- assertEquals("&", w.encodeAttributeValue("&"));
- assertEquals("", w.encodeAttributeValue("\u0017"));
- assertEquals("
	", w.encodeAttributeValue("\r\n\t"));
- }
-
- @Test
- public void testAttributeWithWhitespace() throws IOException {
- Document d = DOMUtils.newDocument();
- Element root = d.createElement("root");
- root.setAttribute("foo", "bar\nbaz");
- StringWriter sw = new StringWriter();
- DOMElementWriter w = new DOMElementWriter();
- w.write(root, sw, 0, " ");
- assertEquals("<root foo=\"bar
baz\" />" + StringUtils.LINE_SEP,
- sw.toString());
- }
-
- @Test
- public void testEncodeData() {
- assertEquals("\"20;&", w.encodedata("\"20;&"));
- assertEquals("", w.encodedata("\u0017"));
- }
-
- @Test
- public void testIsLegalCharacter() {
- assertTrue("0x00", !w.isLegalCharacter('\u0000'));
- assertTrue("0x09", w.isLegalCharacter('\t'));
- assertTrue("0x0A", w.isLegalCharacter('\n'));
- assertTrue("0x0C", w.isLegalCharacter('\r'));
- assertTrue("0x1F", !w.isLegalCharacter('\u001F'));
- assertTrue("0x20", w.isLegalCharacter('\u0020'));
- assertTrue("0xD7FF", w.isLegalCharacter('\uD7FF'));
- assertTrue("0xD800", !w.isLegalCharacter('\uD800'));
- assertTrue("0xDFFF", !w.isLegalCharacter('\uDFFF'));
- assertTrue("0xE000", w.isLegalCharacter('\uE000'));
- assertTrue("0xFFFD", w.isLegalCharacter('\uFFFD'));
- assertTrue("0xFFFE", !w.isLegalCharacter('\uFFFE'));
- }
-
- @Test
- public void testCDATAEndEncoding() {
- assertEquals("]>", w.encodedata("]>"));
- assertEquals("]]", w.encodedata("]]"));
- assertEquals("]]]]><![CDATA[>", w.encodedata("]]>"));
- assertEquals("]]]]><![CDATA[>A", w.encodedata("]]>A"));
- assertEquals("A]]]]><![CDATA[>", w.encodedata("A]]>"));
- assertEquals("A]]]]><![CDATA[>A", w.encodedata("A]]>A"));
- assertEquals("A]]]]><![CDATA[>B]]]]><![CDATA[>C",
- w.encodedata("A]]>B]]>C"));
- }
-
- @Test
- public void testNoAdditionalWhiteSpaceForText() throws IOException {
- Document d = DOMUtils.newDocument();
- Element root = d.createElement("root");
- DOMUtils.appendTextElement(root, "textElement", "content");
-
- StringWriter sw = new StringWriter();
- DOMElementWriter w = new DOMElementWriter();
- w.write(root, sw, 0, " ");
- assertEquals("<root>" + StringUtils.LINE_SEP
- + " <textElement>content</textElement>"
- + StringUtils.LINE_SEP
- + "</root>" + StringUtils.LINE_SEP,
- sw.toString());
- }
-
- @Test
- public void testNoAdditionalWhiteSpaceForCDATA() throws IOException {
- Document d = DOMUtils.newDocument();
- Element root = d.createElement("root");
- DOMUtils.appendCDATAElement(root, "cdataElement", "content");
-
- StringWriter sw = new StringWriter();
- DOMElementWriter w = new DOMElementWriter();
- w.write(root, sw, 0, " ");
- assertEquals("<root>" + StringUtils.LINE_SEP
- + " <cdataElement><![CDATA[content]]></cdataElement>"
- + StringUtils.LINE_SEP
- + "</root>" + StringUtils.LINE_SEP,
- sw.toString());
- }
-
- @Test
- public void testNoAdditionalWhiteSpaceForEmptyElement() throws IOException {
- Document d = DOMUtils.newDocument();
- Element root = d.createElement("root");
- DOMUtils.createChildElement(root, "emptyElement");
-
- StringWriter sw = new StringWriter();
- DOMElementWriter w = new DOMElementWriter();
- w.write(root, sw, 0, " ");
- assertEquals("<root>" + StringUtils.LINE_SEP
- // + " <emptyElement></emptyElement>"
- + " <emptyElement />"
- + StringUtils.LINE_SEP
- + "</root>" + StringUtils.LINE_SEP,
- sw.toString());
- }
-
- @Test
- public void testNoNSPrefixByDefault() throws IOException {
- Document d = DOMUtils.newDocument();
- Element root = d.createElementNS("urn:foo", "root");
- root.setAttributeNS("urn:foo2", "bar", "baz");
-
- StringWriter sw = new StringWriter();
- DOMElementWriter w = new DOMElementWriter();
- w.write(root, sw, 0, " ");
- assertEquals("<root bar=\"baz\" />"
- + StringUtils.LINE_SEP, sw.toString());
- }
-
- @Test
- public void testNSOnElement() throws IOException {
- Document d = DOMUtils.newDocument();
- Element root = d.createElementNS("urn:foo", "root");
- root.setAttributeNS("urn:foo2", "bar", "baz");
-
- StringWriter sw = new StringWriter();
- DOMElementWriter w =
- new DOMElementWriter(false,
- DOMElementWriter.XmlNamespacePolicy
- .ONLY_QUALIFY_ELEMENTS);
- w.write(root, sw, 0, " ");
- assertEquals("<root bar=\"baz\" xmlns=\"urn:foo\" />"
- + StringUtils.LINE_SEP, sw.toString());
- }
-
- @Test
- public void testNSPrefixOnAttribute() throws IOException {
- Document d = DOMUtils.newDocument();
- Element root = d.createElementNS("urn:foo", "root");
- root.setAttributeNS("urn:foo2", "bar", "baz");
-
- StringWriter sw = new StringWriter();
- DOMElementWriter w =
- new DOMElementWriter(false,
- DOMElementWriter.XmlNamespacePolicy
- .QUALIFY_ALL);
- w.write(root, sw, 0, " ");
- assertEquals("<root ns0:bar=\"baz\" xmlns=\"urn:foo\""
- + " xmlns:ns0=\"urn:foo2\" />"
- + StringUtils.LINE_SEP, sw.toString());
- }
-
- @Test
- public void testNSPrefixOnAttributeEvenWithoutElement() throws IOException {
- Document d = DOMUtils.newDocument();
- Element root = d.createElementNS("urn:foo", "root");
- root.setAttributeNS("urn:foo2", "bar", "baz");
-
- StringWriter sw = new StringWriter();
- DOMElementWriter w =
- new DOMElementWriter(false,
- new DOMElementWriter.XmlNamespacePolicy(false,
- true)
- );
- w.write(root, sw, 0, " ");
- assertEquals("<root ns0:bar=\"baz\" xmlns:ns0=\"urn:foo2\" />"
- + StringUtils.LINE_SEP, sw.toString());
- }
-
- @Test
- public void testNSGetsReused() throws IOException {
- Document d = DOMUtils.newDocument();
- Element root = d.createElementNS("urn:foo", "root");
- Element child = d.createElementNS("urn:foo", "child");
- root.appendChild(child);
- StringWriter sw = new StringWriter();
- DOMElementWriter w =
- new DOMElementWriter(false,
- DOMElementWriter.XmlNamespacePolicy
- .ONLY_QUALIFY_ELEMENTS);
- w.write(root, sw, 0, " ");
- assertEquals("<root xmlns=\"urn:foo\">"
- + StringUtils.LINE_SEP
- + " <child />"
- + StringUtils.LINE_SEP
- + "</root>"
- + StringUtils.LINE_SEP, sw.toString());
- }
-
- @Test
- public void testNSGoesOutOfScope() throws IOException {
- Document d = DOMUtils.newDocument();
- Element root = d.createElementNS("urn:foo", "root");
- Element child = d.createElementNS("urn:foo2", "child");
- root.appendChild(child);
- Element child2 = d.createElementNS("urn:foo2", "child");
- root.appendChild(child2);
- Element grandChild = d.createElementNS("urn:foo2", "grandchild");
- child2.appendChild(grandChild);
- Element child3 = d.createElementNS("urn:foo2", "child");
- root.appendChild(child3);
- StringWriter sw = new StringWriter();
- DOMElementWriter w =
- new DOMElementWriter(false,
- DOMElementWriter.XmlNamespacePolicy
- .ONLY_QUALIFY_ELEMENTS);
- w.write(root, sw, 0, " ");
- assertEquals("<root xmlns=\"urn:foo\">"
- + StringUtils.LINE_SEP
- + " <ns0:child xmlns:ns0=\"urn:foo2\" />"
- + StringUtils.LINE_SEP
- + " <ns1:child xmlns:ns1=\"urn:foo2\">"
- + StringUtils.LINE_SEP
- + " <ns1:grandchild />"
- + StringUtils.LINE_SEP
- + " </ns1:child>"
- + StringUtils.LINE_SEP
- + " <ns2:child xmlns:ns2=\"urn:foo2\" />"
- + StringUtils.LINE_SEP
- + "</root>"
- + StringUtils.LINE_SEP, sw.toString());
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.util;
+
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+import java.io.IOException;
+import java.io.StringWriter;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests for org.apache.tools.ant.util.DOMElementWriter.
+ *
+ */
+public class DOMElementWriterTest {
+
+ private DOMElementWriter w = new DOMElementWriter();
+
+ @Test
+ public void testIsReference() {
+ assertTrue("", w.isReference(""));
+ assertTrue(" ", w.isReference(" "));
+ assertTrue(" ", w.isReference(" "));
+ assertTrue("&#A0;", !w.isReference("&#A0;"));
+ assertTrue("20;", !w.isReference("20;"));
+ assertTrue("", !w.isReference(""));
+ assertTrue(""", w.isReference("""));
+ assertTrue("'", w.isReference("'"));
+ assertTrue(">", w.isReference(">"));
+ assertTrue("<", w.isReference("<"));
+ assertTrue("&", w.isReference("&"));
+ }
+
+ @Test
+ public void testEncode() {
+ assertEquals("&#20;", w.encode(""));
+ assertEquals("&#x20;", w.encode(" "));
+ assertEquals("&#xA0;", w.encode(" "));
+ assertEquals("&#A0;", w.encode("&#A0;"));
+ assertEquals("20;", w.encode("20;"));
+ assertEquals("&#20", w.encode(""));
+ assertEquals("&quot;", w.encode("""));
+ assertEquals("&apos;", w.encode("'"));
+ assertEquals("&gt;", w.encode(">"));
+ assertEquals("&lt;", w.encode("<"));
+ assertEquals("&amp;", w.encode("&"));
+ assertEquals(""", w.encode("\""));
+ assertEquals("<", w.encode("<"));
+ assertEquals("&", w.encode("&"));
+ assertEquals("", w.encode("\u0017"));
+ assertEquals("\r\n\t", w.encode("\r\n\t"));
+ }
+
+ @Test
+ public void testEncodeAttributeValue() {
+ assertEquals("&#20;", w.encodeAttributeValue(""));
+ assertEquals("&#x20;", w.encodeAttributeValue(" "));
+ assertEquals("&#xA0;", w.encodeAttributeValue(" "));
+ assertEquals("&#A0;", w.encodeAttributeValue("&#A0;"));
+ assertEquals("20;", w.encodeAttributeValue("20;"));
+ assertEquals("&#20", w.encodeAttributeValue(""));
+ assertEquals("&quot;", w.encodeAttributeValue("""));
+ assertEquals("&apos;", w.encodeAttributeValue("'"));
+ assertEquals("&gt;", w.encodeAttributeValue(">"));
+ assertEquals("&lt;", w.encodeAttributeValue("<"));
+ assertEquals("&amp;", w.encodeAttributeValue("&"));
+ assertEquals(""", w.encodeAttributeValue("\""));
+ assertEquals("<", w.encodeAttributeValue("<"));
+ assertEquals("&", w.encodeAttributeValue("&"));
+ assertEquals("", w.encodeAttributeValue("\u0017"));
+ assertEquals("
	", w.encodeAttributeValue("\r\n\t"));
+ }
+
+ @Test
+ public void testAttributeWithWhitespace() throws IOException {
+ Document d = DOMUtils.newDocument();
+ Element root = d.createElement("root");
+ root.setAttribute("foo", "bar\nbaz");
+ StringWriter sw = new StringWriter();
+ DOMElementWriter w = new DOMElementWriter();
+ w.write(root, sw, 0, " ");
+ assertEquals("<root foo=\"bar
baz\" />" + StringUtils.LINE_SEP,
+ sw.toString());
+ }
+
+ @Test
+ public void testEncodeData() {
+ assertEquals("\"20;&", w.encodedata("\"20;&"));
+ assertEquals("", w.encodedata("\u0017"));
+ }
+
+ @Test
+ public void testIsLegalCharacter() {
+ assertTrue("0x00", !w.isLegalCharacter('\u0000'));
+ assertTrue("0x09", w.isLegalCharacter('\t'));
+ assertTrue("0x0A", w.isLegalCharacter('\n'));
+ assertTrue("0x0C", w.isLegalCharacter('\r'));
+ assertTrue("0x1F", !w.isLegalCharacter('\u001F'));
+ assertTrue("0x20", w.isLegalCharacter('\u0020'));
+ assertTrue("0xD7FF", w.isLegalCharacter('\uD7FF'));
+ assertTrue("0xD800", !w.isLegalCharacter('\uD800'));
+ assertTrue("0xDFFF", !w.isLegalCharacter('\uDFFF'));
+ assertTrue("0xE000", w.isLegalCharacter('\uE000'));
+ assertTrue("0xFFFD", w.isLegalCharacter('\uFFFD'));
+ assertTrue("0xFFFE", !w.isLegalCharacter('\uFFFE'));
+ }
+
+ @Test
+ public void testCDATAEndEncoding() {
+ assertEquals("]>", w.encodedata("]>"));
+ assertEquals("]]", w.encodedata("]]"));
+ assertEquals("]]]]><![CDATA[>", w.encodedata("]]>"));
+ assertEquals("]]]]><![CDATA[>A", w.encodedata("]]>A"));
+ assertEquals("A]]]]><![CDATA[>", w.encodedata("A]]>"));
+ assertEquals("A]]]]><![CDATA[>A", w.encodedata("A]]>A"));
+ assertEquals("A]]]]><![CDATA[>B]]]]><![CDATA[>C",
+ w.encodedata("A]]>B]]>C"));
+ }
+
+ @Test
+ public void testNoAdditionalWhiteSpaceForText() throws IOException {
+ Document d = DOMUtils.newDocument();
+ Element root = d.createElement("root");
+ DOMUtils.appendTextElement(root, "textElement", "content");
+
+ StringWriter sw = new StringWriter();
+ DOMElementWriter w = new DOMElementWriter();
+ w.write(root, sw, 0, " ");
+ assertEquals("<root>" + StringUtils.LINE_SEP
+ + " <textElement>content</textElement>"
+ + StringUtils.LINE_SEP
+ + "</root>" + StringUtils.LINE_SEP,
+ sw.toString());
+ }
+
+ @Test
+ public void testNoAdditionalWhiteSpaceForCDATA() throws IOException {
+ Document d = DOMUtils.newDocument();
+ Element root = d.createElement("root");
+ DOMUtils.appendCDATAElement(root, "cdataElement", "content");
+
+ StringWriter sw = new StringWriter();
+ DOMElementWriter w = new DOMElementWriter();
+ w.write(root, sw, 0, " ");
+ assertEquals("<root>" + StringUtils.LINE_SEP
+ + " <cdataElement><![CDATA[content]]></cdataElement>"
+ + StringUtils.LINE_SEP
+ + "</root>" + StringUtils.LINE_SEP,
+ sw.toString());
+ }
+
+ @Test
+ public void testNoAdditionalWhiteSpaceForEmptyElement() throws IOException {
+ Document d = DOMUtils.newDocument();
+ Element root = d.createElement("root");
+ DOMUtils.createChildElement(root, "emptyElement");
+
+ StringWriter sw = new StringWriter();
+ DOMElementWriter w = new DOMElementWriter();
+ w.write(root, sw, 0, " ");
+ assertEquals("<root>" + StringUtils.LINE_SEP
+ // + " <emptyElement></emptyElement>"
+ + " <emptyElement />"
+ + StringUtils.LINE_SEP
+ + "</root>" + StringUtils.LINE_SEP,
+ sw.toString());
+ }
+
+ @Test
+ public void testNoNSPrefixByDefault() throws IOException {
+ Document d = DOMUtils.newDocument();
+ Element root = d.createElementNS("urn:foo", "root");
+ root.setAttributeNS("urn:foo2", "bar", "baz");
+
+ StringWriter sw = new StringWriter();
+ DOMElementWriter w = new DOMElementWriter();
+ w.write(root, sw, 0, " ");
+ assertEquals("<root bar=\"baz\" />"
+ + StringUtils.LINE_SEP, sw.toString());
+ }
+
+ @Test
+ public void testNSOnElement() throws IOException {
+ Document d = DOMUtils.newDocument();
+ Element root = d.createElementNS("urn:foo", "root");
+ root.setAttributeNS("urn:foo2", "bar", "baz");
+
+ StringWriter sw = new StringWriter();
+ DOMElementWriter w =
+ new DOMElementWriter(false,
+ DOMElementWriter.XmlNamespacePolicy
+ .ONLY_QUALIFY_ELEMENTS);
+ w.write(root, sw, 0, " ");
+ assertEquals("<root bar=\"baz\" xmlns=\"urn:foo\" />"
+ + StringUtils.LINE_SEP, sw.toString());
+ }
+
+ @Test
+ public void testNSPrefixOnAttribute() throws IOException {
+ Document d = DOMUtils.newDocument();
+ Element root = d.createElementNS("urn:foo", "root");
+ root.setAttributeNS("urn:foo2", "bar", "baz");
+
+ StringWriter sw = new StringWriter();
+ DOMElementWriter w =
+ new DOMElementWriter(false,
+ DOMElementWriter.XmlNamespacePolicy
+ .QUALIFY_ALL);
+ w.write(root, sw, 0, " ");
+ assertEquals("<root ns0:bar=\"baz\" xmlns=\"urn:foo\""
+ + " xmlns:ns0=\"urn:foo2\" />"
+ + StringUtils.LINE_SEP, sw.toString());
+ }
+
+ @Test
+ public void testNSPrefixOnAttributeEvenWithoutElement() throws IOException {
+ Document d = DOMUtils.newDocument();
+ Element root = d.createElementNS("urn:foo", "root");
+ root.setAttributeNS("urn:foo2", "bar", "baz");
+
+ StringWriter sw = new StringWriter();
+ DOMElementWriter w =
+ new DOMElementWriter(false,
+ new DOMElementWriter.XmlNamespacePolicy(false,
+ true)
+ );
+ w.write(root, sw, 0, " ");
+ assertEquals("<root ns0:bar=\"baz\" xmlns:ns0=\"urn:foo2\" />"
+ + StringUtils.LINE_SEP, sw.toString());
+ }
+
+ @Test
+ public void testNSGetsReused() throws IOException {
+ Document d = DOMUtils.newDocument();
+ Element root = d.createElementNS("urn:foo", "root");
+ Element child = d.createElementNS("urn:foo", "child");
+ root.appendChild(child);
+ StringWriter sw = new StringWriter();
+ DOMElementWriter w =
+ new DOMElementWriter(false,
+ DOMElementWriter.XmlNamespacePolicy
+ .ONLY_QUALIFY_ELEMENTS);
+ w.write(root, sw, 0, " ");
+ assertEquals("<root xmlns=\"urn:foo\">"
+ + StringUtils.LINE_SEP
+ + " <child />"
+ + StringUtils.LINE_SEP
+ + "</root>"
+ + StringUtils.LINE_SEP, sw.toString());
+ }
+
+ @Test
+ public void testNSGoesOutOfScope() throws IOException {
+ Document d = DOMUtils.newDocument();
+ Element root = d.createElementNS("urn:foo", "root");
+ Element child = d.createElementNS("urn:foo2", "child");
+ root.appendChild(child);
+ Element child2 = d.createElementNS("urn:foo2", "child");
+ root.appendChild(child2);
+ Element grandChild = d.createElementNS("urn:foo2", "grandchild");
+ child2.appendChild(grandChild);
+ Element child3 = d.createElementNS("urn:foo2", "child");
+ root.appendChild(child3);
+ StringWriter sw = new StringWriter();
+ DOMElementWriter w =
+ new DOMElementWriter(false,
+ DOMElementWriter.XmlNamespacePolicy
+ .ONLY_QUALIFY_ELEMENTS);
+ w.write(root, sw, 0, " ");
+ assertEquals("<root xmlns=\"urn:foo\">"
+ + StringUtils.LINE_SEP
+ + " <ns0:child xmlns:ns0=\"urn:foo2\" />"
+ + StringUtils.LINE_SEP
+ + " <ns1:child xmlns:ns1=\"urn:foo2\">"
+ + StringUtils.LINE_SEP
+ + " <ns1:grandchild />"
+ + StringUtils.LINE_SEP
+ + " </ns1:child>"
+ + StringUtils.LINE_SEP
+ + " <ns2:child xmlns:ns2=\"urn:foo2\" />"
+ + StringUtils.LINE_SEP
+ + "</root>"
+ + StringUtils.LINE_SEP, sw.toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/0ed7f4ab/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java
----------------------------------------------------------------------
diff --git a/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java b/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java
index 2e27cde..bcda609 100644
--- a/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java
+++ b/src/tests/junit/org/apache/tools/ant/util/DeweyDecimalTest.java
@@ -1,70 +1,70 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.util;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import org.junit.Test;
-
-@SuppressWarnings("ResultOfObjectAllocationIgnored")
-public class DeweyDecimalTest {
-
- @Test public void parse() {
- assertEquals("1.2.3", new DeweyDecimal("1.2.3").toString());
- }
-
- @Test(expected=NumberFormatException.class) public void misparseEmpty() {
- new DeweyDecimal("1..2");
- }
-
- @Test(expected=NumberFormatException.class) public void misparseNonNumeric() {
- new DeweyDecimal("1.2.3-beta-5");
- }
-
- @Test(expected=NumberFormatException.class) public void misparseFinalDot() {
- new DeweyDecimal("1.2.");
- }
-
- // TODO initial dots, empty string, null, negative numbers, ...
-
- @Test public void testHashCode() {
- assertEquals(new DeweyDecimal("1.2.3").hashCode(), new DeweyDecimal("1.2.3").hashCode());
- }
-
- @Test public void testEquals() {
- assertTrue(new DeweyDecimal("1.2.3").equals(new DeweyDecimal("1.2.3")));
- assertFalse(new DeweyDecimal("1.2.3").equals(new DeweyDecimal("1.2.4")));
- assertTrue(new DeweyDecimal("1.2.0").equals(new DeweyDecimal("1.2")));
- assertTrue(new DeweyDecimal("1.2").equals(new DeweyDecimal("1.2.0")));
- }
-
- @Test public void compareTo() {
- assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.2")) > 0);
- assertTrue(new DeweyDecimal("1.2").compareTo(new DeweyDecimal("1.2.3")) < 0);
- assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.2.3")) == 0);
- assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.1.4")) > 0);
- assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.2.2.9")) > 0);
- assertTrue(new DeweyDecimal("1.2.0").compareTo(new DeweyDecimal("1.2")) == 0);
- assertTrue(new DeweyDecimal("1.2").compareTo(new DeweyDecimal("1.2.0")) == 0);
- }
-
- // TODO isGreaterThan, ...
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.util;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+@SuppressWarnings("ResultOfObjectAllocationIgnored")
+public class DeweyDecimalTest {
+
+ @Test public void parse() {
+ assertEquals("1.2.3", new DeweyDecimal("1.2.3").toString());
+ }
+
+ @Test(expected=NumberFormatException.class) public void misparseEmpty() {
+ new DeweyDecimal("1..2");
+ }
+
+ @Test(expected=NumberFormatException.class) public void misparseNonNumeric() {
+ new DeweyDecimal("1.2.3-beta-5");
+ }
+
+ @Test(expected=NumberFormatException.class) public void misparseFinalDot() {
+ new DeweyDecimal("1.2.");
+ }
+
+ // TODO initial dots, empty string, null, negative numbers, ...
+
+ @Test public void testHashCode() {
+ assertEquals(new DeweyDecimal("1.2.3").hashCode(), new DeweyDecimal("1.2.3").hashCode());
+ }
+
+ @Test public void testEquals() {
+ assertTrue(new DeweyDecimal("1.2.3").equals(new DeweyDecimal("1.2.3")));
+ assertFalse(new DeweyDecimal("1.2.3").equals(new DeweyDecimal("1.2.4")));
+ assertTrue(new DeweyDecimal("1.2.0").equals(new DeweyDecimal("1.2")));
+ assertTrue(new DeweyDecimal("1.2").equals(new DeweyDecimal("1.2.0")));
+ }
+
+ @Test public void compareTo() {
+ assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.2")) > 0);
+ assertTrue(new DeweyDecimal("1.2").compareTo(new DeweyDecimal("1.2.3")) < 0);
+ assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.2.3")) == 0);
+ assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.1.4")) > 0);
+ assertTrue(new DeweyDecimal("1.2.3").compareTo(new DeweyDecimal("1.2.2.9")) > 0);
+ assertTrue(new DeweyDecimal("1.2.0").compareTo(new DeweyDecimal("1.2")) == 0);
+ assertTrue(new DeweyDecimal("1.2").compareTo(new DeweyDecimal("1.2.0")) == 0);
+ }
+
+ // TODO isGreaterThan, ...
+
+}