feat(serialize-xml): port formatting tests
This commit is contained in:
parent
5e89193244
commit
2a9a6300ef
|
@ -365,4 +365,62 @@ public final class NativeXmlWriterTest {
|
||||||
writer.close();
|
writer.close();
|
||||||
writer.close();
|
writer.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testSetGetFormattingStyle() throws IOException {
|
||||||
|
String lineSeparator = "\r\n";
|
||||||
|
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
NativeXmlWriter jsonWriter = new NativeXmlWriter(stringWriter);
|
||||||
|
// Default should be FormattingStyle.COMPACT
|
||||||
|
jsonWriter.setIndent(" \t ").setNewline(lineSeparator);
|
||||||
|
|
||||||
|
jsonWriter.beginTag("tag");
|
||||||
|
jsonWriter.text("true");
|
||||||
|
jsonWriter.text("text");
|
||||||
|
jsonWriter.text("5.0");
|
||||||
|
jsonWriter.text(null);
|
||||||
|
jsonWriter.endTag();
|
||||||
|
|
||||||
|
String expected = """
|
||||||
|
<tag>\r
|
||||||
|
\t true\r
|
||||||
|
\t <!---->\r
|
||||||
|
\t text\r
|
||||||
|
\t <!---->\r
|
||||||
|
\t 5.0\r
|
||||||
|
\t <!---->\r
|
||||||
|
\t null\r
|
||||||
|
</tag>""";
|
||||||
|
assertThat(stringWriter.toString()).isEqualTo(expected);
|
||||||
|
|
||||||
|
assertThat(jsonWriter.getNewline()).isEqualTo(lineSeparator);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testIndentOverwritesFormattingStyle() throws IOException {
|
||||||
|
StringWriter stringWriter = new StringWriter();
|
||||||
|
NativeXmlWriter jsonWriter = new NativeXmlWriter(stringWriter);
|
||||||
|
// Should overwrite formatting style
|
||||||
|
jsonWriter.setIndent(" ");
|
||||||
|
|
||||||
|
jsonWriter.beginTag("tag");
|
||||||
|
jsonWriter.attributeName("a");
|
||||||
|
jsonWriter.attributeValue("b");
|
||||||
|
jsonWriter.beginTag("tag");
|
||||||
|
jsonWriter.text("1");
|
||||||
|
jsonWriter.text("2");
|
||||||
|
jsonWriter.endTag();
|
||||||
|
jsonWriter.endTag();
|
||||||
|
|
||||||
|
String expected = """
|
||||||
|
<tag a="b">
|
||||||
|
<tag>
|
||||||
|
1
|
||||||
|
<!---->
|
||||||
|
2
|
||||||
|
</tag>
|
||||||
|
</tag>""";
|
||||||
|
assertThat(stringWriter.toString()).isEqualTo(expected);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue