aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2016-01-02 14:16:09 +0000
committerMichael Williamson <mike@zwobble.org>2016-01-02 14:16:09 +0000
commit02ac29cbd29ff95c7174981edaea213e2b7315c7 (patch)
treefcd1144db5822b164f010e3eebf7ab1adb244dec /src/test/java/org
parentba3bb715394a03ea2320cc3679881a0f1548ed99 (diff)
Parse children of run
Diffstat (limited to 'src/test/java/org')
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java28
1 files changed, 27 insertions, 1 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
index 2b6323e..8b04b51 100644
--- a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
+++ b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java
@@ -4,8 +4,12 @@ import com.google.common.collect.ImmutableList;
import org.hamcrest.Matcher;
import org.junit.Test;
import org.zwobble.mammoth.documents.DocumentElement;
+import org.zwobble.mammoth.documents.RunElement;
import org.zwobble.mammoth.documents.TextElement;
import org.zwobble.mammoth.xml.XmlElement;
+import org.zwobble.mammoth.xml.XmlNode;
+
+import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.*;
@@ -16,10 +20,32 @@ import static org.zwobble.mammoth.xml.XmlNodes.text;
public class BodyXmlTests {
@Test
public void textFromTextElementIsRead() {
- XmlElement element = element("w:t", ImmutableList.of(text("Hello!")));
+ XmlElement element = textXml("Hello!");
assertThat(readBodyXmlElement(element), isTextElement("Hello!"));
}
+ @Test
+ public void canReadTextWithinRun() {
+ XmlElement element = runXml(ImmutableList.of(textXml("Hello!")));
+ assertThat(
+ readBodyXmlElement(element),
+ isRunElement(isTextElement("Hello!")));
+ }
+
+ private XmlElement runXml(List<XmlNode> children) {
+ return element("w:r", children);
+ }
+
+ private XmlElement textXml(String value) {
+ return element("w:t", ImmutableList.of(text(value)));
+ }
+
+ private Matcher<DocumentElement> isRunElement(Matcher<DocumentElement> child) {
+ return allOf(
+ instanceOf(RunElement.class),
+ hasProperty("children", contains(child)));
+ }
+
private Matcher<DocumentElement> isTextElement(String value) {
return allOf(
instanceOf(TextElement.class),