-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove special chars from xml output
--------- Co-authored-by: Michael Osipov <[email protected]> (cherry picked from commit c9d72af)
- Loading branch information
1 parent
4274b2e
commit be6885b
Showing
4 changed files
with
93 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
src/test/java/org/codehaus/plexus/util/xml/pull/MXSerializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package org.codehaus.plexus.util.xml.pull; | ||
|
||
import java.io.StringReader; | ||
import java.io.StringWriter; | ||
import java.util.Arrays; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
class MXSerializerTest { | ||
|
||
@Test | ||
void testSerialize() throws Exception { | ||
|
||
StringWriter writer = new StringWriter(); | ||
|
||
MXSerializer sr = new MXSerializer(); | ||
sr.setOutput(writer); | ||
|
||
sr.startDocument(null, Boolean.TRUE); | ||
sr.startTag(null, "root"); | ||
for (int i : Arrays.asList(8, 9, 10, 11, 13, 15)) { | ||
sr.startTag(null, "char"); | ||
sr.text(Character.getName(i) + ": " + ((char) i)); | ||
sr.endTag(null, "char"); | ||
} | ||
|
||
sr.endTag(null, "root"); | ||
sr.endDocument(); | ||
assertEquals(expectedOutput(), writer.toString()); | ||
} | ||
|
||
@Test | ||
void testDeserialize() throws Exception { | ||
MXParser parser = new MXParser(); | ||
parser.setInput(new StringReader(expectedOutput())); | ||
int eventType = parser.getEventType(); | ||
|
||
while (eventType != XmlPullParser.END_DOCUMENT) { | ||
eventType = parser.next(); | ||
} | ||
} | ||
|
||
private String expectedOutput() { | ||
StringBuilder out = new StringBuilder(); | ||
out.append("<?xml version=\"1.0\" standalone=\"yes\"?>"); | ||
out.append("<root>"); | ||
out.append("<char>BACKSPACE: </char>"); | ||
out.append("<char>CHARACTER TABULATION: \t</char>"); | ||
out.append("<char>LINE FEED (LF): \n</char>"); | ||
out.append("<char>LINE TABULATION: </char>"); | ||
out.append("<char>CARRIAGE RETURN (CR): \r</char>"); | ||
out.append("<char>SHIFT IN: </char>"); | ||
out.append("</root>"); | ||
return out.toString(); | ||
} | ||
} |