From 8377b89bfc97a85dbe90fb4cfa5dd33cd3568af4 Mon Sep 17 00:00:00 2001 From: Michael Williamson Date: Sun, 21 Feb 2016 10:09:47 +0000 Subject: Add style mappings for runs --- .../mammoth/tests/DocumentConverterTests.java | 28 ++++++++++++++++++++++ .../tests/documents/DocumentElementMakers.java | 16 ++++++------- 2 files changed, 36 insertions(+), 8 deletions(-) (limited to 'src/test/java/org/zwobble/mammoth') diff --git a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java index bc37ad9..95fbe5d 100644 --- a/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java @@ -8,6 +8,7 @@ import org.zwobble.mammoth.html.HtmlNode; import org.zwobble.mammoth.results.Result; import org.zwobble.mammoth.styles.HtmlPath; import org.zwobble.mammoth.styles.ParagraphMatcher; +import org.zwobble.mammoth.styles.RunMatcher; import org.zwobble.mammoth.styles.StyleMap; import java.io.ByteArrayInputStream; @@ -80,6 +81,33 @@ public class DocumentConverterTests { list(warning("Unrecognised paragraph style: Tips Paragraph (Style ID: TipsParagraph)"))))); } + @Test + public void runStyleMappingsCanBeUsedToMapRuns() { + assertThat( + convertToHtml( + make(a(RUN, with(STYLE, Optional.of(new Style("TipsRun", Optional.empty()))))), + StyleMap.builder() + .mapRun( + RunMatcher.styleId("TipsRun"), + HtmlPath.element("span", map("class", "tip"))) + .build()), + + deepEquals(list(Html.element("span", map("class", "tip"))))); + } + + @Test + public void warningIfRunHasUnrecognisedStyle() { + assertThat( + convertToHtmlResult( + make(a(RUN, + with(STYLE, Optional.of(new Style("TipsRun", Optional.of("Tips Run")))), + with(CHILDREN, list(new Text("Hello")))))), + + deepEquals(new Result<>( + list(Html.text("Hello")), + list(warning("Unrecognised run style: Tips Run (Style ID: TipsRun)"))))); + } + @Test public void boldRunsAreWrappedInStrongTags() { assertThat( 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 a80e2ea..683251d 100644 --- a/src/test/java/org/zwobble/mammoth/tests/documents/DocumentElementMakers.java +++ b/src/test/java/org/zwobble/mammoth/tests/documents/DocumentElementMakers.java @@ -14,13 +14,13 @@ import static com.natpryce.makeiteasy.Property.newProperty; import static org.zwobble.mammoth.util.MammothLists.list; public class DocumentElementMakers { - public static final Property> STYLE = newProperty(); - public static final Property> NUMBERING = newProperty(); - public static final Property BOLD = newProperty(); - public static final Property ITALIC = newProperty(); - public static final Property UNDERLINE = newProperty(); - public static final Property STRIKETHROUGH = newProperty(); - public static final Property VERTICAL_ALIGNMENT = newProperty(); + public static final Property> STYLE = newProperty(); + public static final Property> NUMBERING = newProperty(); + public static final Property BOLD = newProperty(); + public static final Property ITALIC = newProperty(); + public static final Property UNDERLINE = newProperty(); + public static final Property STRIKETHROUGH = newProperty(); + public static final Property VERTICAL_ALIGNMENT = newProperty(); public static final Property> CHILDREN = newProperty(); public static final Instantiator PARAGRAPH = @@ -36,7 +36,7 @@ public class DocumentElementMakers { propertyLookup.valueOf(UNDERLINE, false), propertyLookup.valueOf(STRIKETHROUGH, false), propertyLookup.valueOf(VERTICAL_ALIGNMENT, VerticalAlignment.BASELINE), - Optional.empty(), + propertyLookup.valueOf(STYLE, Optional.empty()), propertyLookup.valueOf(CHILDREN, list())); public static Paragraph paragraphWithText(String text) { -- cgit v1.2.3