diff options
| author | Michael Williamson <mike@zwobble.org> | 2015-09-26 17:33:13 +0100 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2015-09-26 17:33:13 +0100 |
| commit | be6fbc6f4e2f80552d3a7bab8677066d1fc858fc (patch) | |
| tree | 365f33cb3c09e838ff7bfab33609c919b73508ac /src/test/java/org/zwobble/mammoth/tests/xml | |
| parent | 0cdeb56333f61fc5769749106496106cfd8ffbfe (diff) | |
Add simple XML parsing
Diffstat (limited to 'src/test/java/org/zwobble/mammoth/tests/xml')
| -rw-r--r-- | src/test/java/org/zwobble/mammoth/tests/xml/XmlParserTests.java | 59 |
1 files changed, 59 insertions, 0 deletions
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("<body/>"), + is(new XmlElement("body"))); + assertThat( + XmlParser.parseString("<values/>"), + is(new XmlElement("values"))); + } + + @Test + public void canParseEmptyElementWithSeparateClosingTag() { + assertThat( + XmlParser.parseString("<body></body>"), + is(new XmlElement("body"))); + } + + @Test + public void canParseAttributesOfTag() { + assertThat( + XmlParser.parseString("<body name='bob'></body>"), + is(new XmlElement("body", ImmutableMap.of("name", "bob")))); + } + + @Test + public void canParseElementWithDescendantElements() { + assertThat( + XmlParser.parseString("<body><a><b/></a><a/></body>"), + 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("<body>Hello!</body>"), + is(new XmlElement("body", ImmutableMap.of(), ImmutableList.of( + new XmlTextNode("Hello!") + )))); + } +} |
