diff options
| author | Michael Williamson <mike@zwobble.org> | 2016-02-21 10:09:47 +0000 |
|---|---|---|
| committer | Michael Williamson <mike@zwobble.org> | 2016-02-21 10:09:47 +0000 |
| commit | 8377b89bfc97a85dbe90fb4cfa5dd33cd3568af4 (patch) | |
| tree | c37ec926bfb9cf2c45ebfb564edb596fa1e0965a /src/test/java/org/zwobble | |
| parent | c1604e510cc831a00f6105df35c68a856f061b65 (diff) | |
Add style mappings for runs
Diffstat (limited to 'src/test/java/org/zwobble')
| -rw-r--r-- | src/test/java/org/zwobble/mammoth/tests/DocumentConverterTests.java | 28 | ||||
| -rw-r--r-- | src/test/java/org/zwobble/mammoth/tests/documents/DocumentElementMakers.java | 16 |
2 files changed, 36 insertions, 8 deletions
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; @@ -81,6 +82,33 @@ public class DocumentConverterTests { } @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( convertToHtml(make(a(RUN, with(BOLD, true), with(CHILDREN, list(new Text("Hello")))))), 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<HasChildren, Optional<Style>> STYLE = newProperty(); - public static final Property<HasChildren, Optional<NumberingLevel>> NUMBERING = newProperty(); - public static final Property<HasChildren, Boolean> BOLD = newProperty(); - public static final Property<HasChildren, Boolean> ITALIC = newProperty(); - public static final Property<HasChildren, Boolean> UNDERLINE = newProperty(); - public static final Property<HasChildren, Boolean> STRIKETHROUGH = newProperty(); - public static final Property<HasChildren, VerticalAlignment> VERTICAL_ALIGNMENT = newProperty(); + public static final Property<DocumentElement, Optional<Style>> STYLE = newProperty(); + public static final Property<Paragraph, Optional<NumberingLevel>> NUMBERING = newProperty(); + public static final Property<Run, Boolean> BOLD = newProperty(); + public static final Property<Run, Boolean> ITALIC = newProperty(); + public static final Property<Run, Boolean> UNDERLINE = newProperty(); + public static final Property<Run, Boolean> STRIKETHROUGH = newProperty(); + public static final Property<Run, VerticalAlignment> VERTICAL_ALIGNMENT = newProperty(); public static final Property<HasChildren, List<DocumentElement>> CHILDREN = newProperty(); public static final Instantiator<Paragraph> 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) { |
