From 90680b0208bba24a970f8b7fd6f9092f5ca90407 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Mon, 2 May 2016 12:07:36 +0100 Subject: Read colspan for table cells --- .../mammoth/tests/DeepReflectionMatcher.java | 4 +-- .../tests/conversion/DocumentToHtmlTests.java | 8 +++--- .../tests/documents/DocumentElementMakers.java | 10 ++++++++ .../zwobble/mammoth/tests/docx/BodyXmlTests.java | 30 ++++++++++++++++++++-- 4 files changed, 44 insertions(+), 8 deletions(-) (limited to 'src/test/java') diff --git a/src/test/java/org/zwobble/mammoth/tests/DeepReflectionMatcher.java b/src/test/java/org/zwobble/mammoth/tests/DeepReflectionMatcher.java index 94bd05a..26414ac 100644 --- a/src/test/java/org/zwobble/mammoth/tests/DeepReflectionMatcher.java +++ b/src/test/java/org/zwobble/mammoth/tests/DeepReflectionMatcher.java @@ -62,7 +62,7 @@ public class DeepReflectionMatcher extends TypeSafeDiagnosingMatcher { return matchesOptional(path, (Optional)expected, (Optional)actual, mismatchDescription); } - if (expected instanceof String || expected instanceof Boolean || expected instanceof Enum) { + if (expected instanceof String || expected instanceof Boolean || expected instanceof Enum || expected instanceof Integer) { return matchesPrimitive(path, expected, actual, mismatchDescription); } @@ -196,7 +196,7 @@ public class DeepReflectionMatcher extends TypeSafeDiagnosingMatcher { } private static String describeValue(Object value) { - if (value instanceof String || value instanceof Boolean) { + if (value instanceof String || value instanceof Boolean || value instanceof Integer) { return value.toString(); } else if (value instanceof Optional) { Optional optional = (Optional)value; diff --git a/src/test/java/org/zwobble/mammoth/tests/conversion/DocumentToHtmlTests.java b/src/test/java/org/zwobble/mammoth/tests/conversion/DocumentToHtmlTests.java index 72a75d3..2260f0d 100644 --- a/src/test/java/org/zwobble/mammoth/tests/conversion/DocumentToHtmlTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/conversion/DocumentToHtmlTests.java @@ -207,11 +207,11 @@ public class DocumentToHtmlTests { assertThat( convertToHtml(new Table(list( new TableRow(list( - new TableCell(list(paragraphWithText("Top left"))), - new TableCell(list(paragraphWithText("Top right"))))), + tableCell(list(paragraphWithText("Top left"))), + tableCell(list(paragraphWithText("Top right"))))), new TableRow(list( - new TableCell(list(paragraphWithText("Bottom left"))), - new TableCell(list(paragraphWithText("Bottom right")))))))), + tableCell(list(paragraphWithText("Bottom left"))), + tableCell(list(paragraphWithText("Bottom right")))))))), deepEquals(list(Html.element("table", list( Html.element("tr", list( diff --git a/src/test/java/org/zwobble/mammoth/tests/documents/DocumentElementMakers.java b/src/test/java/org/zwobble/mammoth/tests/documents/DocumentElementMakers.java index 3048acd..04d8aef 100644 --- a/src/test/java/org/zwobble/mammoth/tests/documents/DocumentElementMakers.java +++ b/src/test/java/org/zwobble/mammoth/tests/documents/DocumentElementMakers.java @@ -22,6 +22,7 @@ public class DocumentElementMakers { public static final Property STRIKETHROUGH = newProperty(); public static final Property VERTICAL_ALIGNMENT = newProperty(); public static final Property> CHILDREN = newProperty(); + public static final Property COLSPAN = newProperty(); public static final Instantiator PARAGRAPH = propertyLookup -> new Paragraph( @@ -39,6 +40,15 @@ public class DocumentElementMakers { propertyLookup.valueOf(STYLE, Optional.empty()), propertyLookup.valueOf(CHILDREN, list())); + public static final Instantiator TABLE_CELL = + propertyLookup -> new TableCell( + propertyLookup.valueOf(COLSPAN, 1), + propertyLookup.valueOf(CHILDREN, list())); + + public static TableCell tableCell(List children) { + return make(a(TABLE_CELL, with(CHILDREN, children))); + } + public static Paragraph paragraphWithText(String text) { return make(a(PARAGRAPH, with(CHILDREN, list(runWithText(text))))); } 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 6c4d6b5..0752d3a 100644 --- a/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/docx/BodyXmlTests.java @@ -324,8 +324,34 @@ public class BodyXmlTests { readSuccess(a(bodyReader), element), deepEquals(new Table(list( new TableRow(list( - new TableCell(list( - make(a(PARAGRAPH)))))))))); + new TableCell(1, list( + make(a(PARAGRAPH)) + )) + )) + ))) + ); + } + + @Test + public void gridspanIsReadAsColspanForTableCell() { + XmlElement element = element("w:tbl", list( + element("w:tr", list( + element("w:tc", list( + element("w:tcPr", list( + element("w:gridSpan", map("w:val", "2")) + )), + element("w:p"))))))); + + assertThat( + readSuccess(a(bodyReader), element), + deepEquals(new Table(list( + new TableRow(list( + new TableCell(2, list( + make(a(PARAGRAPH)) + )) + )) + ))) + ); } @Test -- cgit v1.2.3