diff options
Diffstat (limited to 'src/test/java/org/zwobble')
| -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!") + )))); + } +} |
