From 53f27cf1a80151bbf06fa9e900c744f06e907f77 Mon Sep 17 00:00:00 2001
From: Michael Williamson
Date: Sat, 26 Sep 2015 17:47:01 +0100
Subject: Allow namespacing mapping in element names
---
.../zwobble/mammoth/tests/xml/XmlParserTests.java | 37 +++++++++++++++++-----
1 file changed, 29 insertions(+), 8 deletions(-)
(limited to 'src/test')
diff --git a/src/test/java/org/zwobble/mammoth/tests/xml/XmlParserTests.java b/src/test/java/org/zwobble/mammoth/tests/xml/XmlParserTests.java
index ff5072f..6b3343d 100644
--- a/src/test/java/org/zwobble/mammoth/tests/xml/XmlParserTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/xml/XmlParserTests.java
@@ -5,41 +5,46 @@ 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;
+import lombok.val;
+
public class XmlParserTests {
+ private final XmlParser parser = new XmlParser(ImmutableBiMap.of());
+
@Test
public void canParseSelfClosingElement() {
assertThat(
- XmlParser.parseString(""),
+ parser.parseString("
"),
+ parser.parseString(""),
is(new XmlElement("body")));
}
@Test
public void canParseAttributesOfTag() {
assertThat(
- XmlParser.parseString(""),
+ parser.parseString(""),
is(new XmlElement("body", ImmutableMap.of("name", "bob"))));
}
@Test
public void canParseElementWithDescendantElements() {
assertThat(
- XmlParser.parseString(""),
+ parser.parseString(""),
is(new XmlElement("body", ImmutableMap.of(), ImmutableList.of(
new XmlElement("a", ImmutableMap.of(), ImmutableList.of(
new XmlElement("b")
@@ -51,7 +56,7 @@ public class XmlParserTests {
@Test
public void canParseTextNodes() {
assertThat(
- XmlParser.parseString("Hello!"),
+ parser.parseString("Hello!"),
is(new XmlElement("body", ImmutableMap.of(), ImmutableList.of(
new XmlTextNode("Hello!")
))));
@@ -60,14 +65,30 @@ public class XmlParserTests {
@Test
public void unmappedNamespaceUrisInElementNamesAreIncludedInBracesAsPrefix() {
assertThat(
- XmlParser.parseString(""),
+ parser.parseString(""),
is(new XmlElement("{word}body")));
}
@Test
public void unmappedNamespaceUrisInAttributeNamesAreIncludedInBracesAsPrefix() {
assertThat(
- XmlParser.parseString(""),
+ parser.parseString(""),
is(new XmlElement("body", ImmutableMap.of("{word}name", "bob"))));
}
+
+ @Test
+ public void mappedNamespaceUrisInElementNamesArePrefixedToLocalNameWithColon() {
+ val parser = new XmlParser(ImmutableBiMap.of("x", "word"));
+ assertThat(
+ parser.parseString(""),
+ is(new XmlElement("x:body")));
+ }
+
+ @Test
+ public void mappedNamespaceUrisInAttributeNamesArePrefixedToLocalNameWithColon() {
+ val parser = new XmlParser(ImmutableBiMap.of("x", "word"));
+ assertThat(
+ parser.parseString("