package org.zwobble.mammoth.tests.xml; import java.io.ByteArrayInputStream; 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.ImmutableBiMap; 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 { private final XmlParser parser = new XmlParser(ImmutableBiMap.of()); @Test public void canParseSelfClosingElement() { assertThat( parser.parseString("
"), is(new XmlElement("body"))); } @Test public void canParseAttributesOfTag() { assertThat( parser.parseString(""), is(new XmlElement("body", ImmutableMap.of("name", "bob")))); } @Test public void canParseElementWithDescendantElements() { assertThat( parser.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( parser.parseString("Hello!"), is(new XmlElement("body", ImmutableMap.of(), ImmutableList.of( new XmlTextNode("Hello!") )))); } @Test public void unmappedNamespaceUrisInElementNamesAreIncludedInBracesAsPrefix() { assertThat( parser.parseString("