From be6fbc6f4e2f80552d3a7bab8677066d1fc858fc Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sat, 26 Sep 2015 17:33:13 +0100 Subject: Add simple XML parsing --- .../zwobble/mammoth/tests/xml/XmlParserTests.java | 59 ++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 src/test/java/org/zwobble/mammoth/tests/xml/XmlParserTests.java (limited to 'src/test/java/org') diff --git a/src/test/java/org/zwobble/mammoth/tests/xml/XmlParserTests.java b/src/test/java/org/zwobble/mammoth/tests/xml/XmlParserTests.java new file mode 100644 index 0000000..1ce5d7d --- /dev/null +++ b/src/test/java/org/zwobble/mammoth/tests/xml/XmlParserTests.java @@ -0,0 +1,59 @@ +package org.zwobble.mammoth.tests.xml; + +import org.junit.Test; +import org.zwobble.mammoth.xml.XmlElement; +import org.zwobble.mammoth.xml.XmlParser; +import org.zwobble.mammoth.xml.XmlTextNode; + +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; + +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThat; + +public class XmlParserTests { + @Test + public void canParseSelfClosingElement() { + assertThat( + XmlParser.parseString(""), + is(new XmlElement("body"))); + assertThat( + XmlParser.parseString(""), + is(new XmlElement("values"))); + } + + @Test + public void canParseEmptyElementWithSeparateClosingTag() { + assertThat( + XmlParser.parseString(""), + is(new XmlElement("body"))); + } + + @Test + public void canParseAttributesOfTag() { + assertThat( + XmlParser.parseString(""), + is(new XmlElement("body", ImmutableMap.of("name", "bob")))); + } + + @Test + public void canParseElementWithDescendantElements() { + assertThat( + XmlParser.parseString(""), + is(new XmlElement("body", ImmutableMap.of(), ImmutableList.of( + new XmlElement("a", ImmutableMap.of(), ImmutableList.of( + new XmlElement("b") + )), + new XmlElement("a") + )))); + } + + @Test + public void canParseTextNodes() { + assertThat( + XmlParser.parseString("Hello!"), + is(new XmlElement("body", ImmutableMap.of(), ImmutableList.of( + new XmlTextNode("Hello!") + )))); + } +} -- cgit v1.2.3