Browse Source

fix extraneous whitespace, should fix svn-antlib tests

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@348913 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 19 years ago
parent
commit
998099d11f
2 changed files with 55 additions and 2 deletions
  1. +3
    -1
      src/main/org/apache/tools/ant/util/DOMElementWriter.java
  2. +52
    -1
      src/testcases/org/apache/tools/ant/util/DOMElementWriterTest.java

+ 3
- 1
src/main/org/apache/tools/ant/util/DOMElementWriter.java View File

@@ -103,6 +103,7 @@ public class DOMElementWriter {
// Write child elements and text
NodeList children = element.getChildNodes();
boolean hasChildren = (children.getLength() > 0);
boolean hasChildElements = false;
openElement(element, out, indent, indentWith, hasChildren);

if (hasChildren) {
@@ -112,6 +113,7 @@ public class DOMElementWriter {
switch (child.getNodeType()) {
case Node.ELEMENT_NODE:
hasChildElements = true;
if (i == 0) {
out.write(lSep);
}
@@ -154,7 +156,7 @@ public class DOMElementWriter {
// Do nothing
}
}
closeElement(element, out, indent, indentWith, true);
closeElement(element, out, indent, indentWith, hasChildElements);
}
}



+ 52
- 1
src/testcases/org/apache/tools/ant/util/DOMElementWriterTest.java View File

@@ -1,5 +1,5 @@
/*
* Copyright 2000-2004 The Apache Software Foundation
* Copyright 2000-2005 The Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -17,9 +17,13 @@

package org.apache.tools.ant.util;

import java.io.IOException;
import java.io.StringWriter;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

/**
* Tests for org.apache.tools.ant.util.DOMElementWriter.
@@ -92,4 +96,51 @@ public class DOMElementWriterTest extends TestCase {
assertEquals("A]]>B]]>C",
w.encodedata("A]]>B]]>C"));
}

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());
}

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());
}

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());
}

}

Loading…
Cancel
Save