diff options
Diffstat (limited to 'src/test')
4 files changed, 69 insertions, 34 deletions
diff --git a/src/test/java/org/zwobble/mammoth/tests/html/HtmlCollapseTests.java b/src/test/java/org/zwobble/mammoth/tests/html/HtmlCollapseTests.java index 83c785d..4d2b5d3 100644 --- a/src/test/java/org/zwobble/mammoth/tests/html/HtmlCollapseTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/html/HtmlCollapseTests.java @@ -2,6 +2,7 @@ package org.zwobble.mammoth.tests.html; import org.junit.Test; import org.zwobble.mammoth.internal.html.Html; +import org.zwobble.mammoth.tests.styles.parsing.HtmlElementBuilder; import static org.hamcrest.MatcherAssert.assertThat; import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals; @@ -95,4 +96,22 @@ public class HtmlCollapseTests { Html.collapsibleElement(list("ul", "ol")), Html.collapsibleElement("ol")))); } + + @Test + public void whenSeparatorIsPresentThenSeparatorIsPrependedToCollapsedElement() { + assertThat( + Html.collapse(list( + HtmlElementBuilder.fresh("pre").element(list(Html.text("Hello"))), + HtmlElementBuilder.collapsible("pre").separator("\n").element(list(Html.text(" the"), Html.text("re"))) + )), + deepEquals(list( + HtmlElementBuilder.fresh("pre").element(list( + Html.text("Hello"), + Html.text("\n"), + Html.text(" the"), + Html.text("re") + )) + )) + ); + } } diff --git a/src/test/java/org/zwobble/mammoth/tests/styles/parsing/HtmlElementBuilder.java b/src/test/java/org/zwobble/mammoth/tests/styles/parsing/HtmlElementBuilder.java new file mode 100644 index 0000000..7ef17ab --- /dev/null +++ b/src/test/java/org/zwobble/mammoth/tests/styles/parsing/HtmlElementBuilder.java @@ -0,0 +1,47 @@ +package org.zwobble.mammoth.tests.styles.parsing; + +import org.zwobble.mammoth.internal.html.HtmlElement; +import org.zwobble.mammoth.internal.html.HtmlNode; +import org.zwobble.mammoth.internal.html.HtmlTag; +import org.zwobble.mammoth.internal.styles.HtmlPathElement; + +import java.util.List; + +import static org.zwobble.mammoth.internal.util.Lists.list; +import static org.zwobble.mammoth.internal.util.Maps.map; + +public class HtmlElementBuilder { + public static HtmlElementBuilder collapsible(String tagName) { + return new HtmlElementBuilder(tagName, true, ""); + } + + public static HtmlElementBuilder fresh(String tagName) { + return new HtmlElementBuilder(tagName, false, ""); + } + + private final String tagName; + private final boolean isCollapsible; + private final String separator; + + public HtmlElementBuilder(String tagName, boolean isCollapsible, String separator) { + this.tagName = tagName; + this.isCollapsible = isCollapsible; + this.separator = separator; + } + + public HtmlElementBuilder separator(String separator) { + return new HtmlElementBuilder(tagName, isCollapsible, separator); + } + + public HtmlPathElement pathElement() { + return new HtmlPathElement(tag()); + } + + public HtmlElement element(List<HtmlNode> children) { + return new HtmlElement(tag(), children); + } + + private HtmlTag tag() { + return new HtmlTag(list(tagName), map(), isCollapsible, separator); + } +} diff --git a/src/test/java/org/zwobble/mammoth/tests/styles/parsing/HtmlPathElementBuilder.java b/src/test/java/org/zwobble/mammoth/tests/styles/parsing/HtmlPathElementBuilder.java deleted file mode 100644 index ec1962c..0000000 --- a/src/test/java/org/zwobble/mammoth/tests/styles/parsing/HtmlPathElementBuilder.java +++ /dev/null @@ -1,31 +0,0 @@ -package org.zwobble.mammoth.tests.styles.parsing; - -import org.zwobble.mammoth.internal.html.HtmlTag; -import org.zwobble.mammoth.internal.styles.HtmlPathElement; - -import static org.zwobble.mammoth.internal.util.Lists.list; -import static org.zwobble.mammoth.internal.util.Maps.map; - -public class HtmlPathElementBuilder { - public static HtmlPathElementBuilder collapsible(String tagName) { - return new HtmlPathElementBuilder(tagName, true, ""); - } - - private final String tagName; - private final boolean isCollapsible; - private final String separator; - - public HtmlPathElementBuilder(String tagName, boolean isCollapsible, String separator) { - this.tagName = tagName; - this.isCollapsible = isCollapsible; - this.separator = separator; - } - - public HtmlPathElementBuilder separator(String separator) { - return new HtmlPathElementBuilder(tagName, isCollapsible, separator); - } - - public HtmlPathElement build() { - return new HtmlPathElement(new HtmlTag(list(tagName), map(), isCollapsible, separator)); - } -} diff --git a/src/test/java/org/zwobble/mammoth/tests/styles/parsing/HtmlPathParsingTests.java b/src/test/java/org/zwobble/mammoth/tests/styles/parsing/HtmlPathParsingTests.java index 53acbba..0b54ad8 100644 --- a/src/test/java/org/zwobble/mammoth/tests/styles/parsing/HtmlPathParsingTests.java +++ b/src/test/java/org/zwobble/mammoth/tests/styles/parsing/HtmlPathParsingTests.java @@ -42,8 +42,8 @@ public class HtmlPathParsingTests { assertThat( parseHtmlPath("ul > li"), deepEquals(HtmlPath.elements( - HtmlPathElementBuilder.collapsible("ul").build(), - HtmlPathElementBuilder.collapsible("li").build() + HtmlElementBuilder.collapsible("ul").pathElement(), + HtmlElementBuilder.collapsible("li").pathElement() ))); } @@ -72,7 +72,7 @@ public class HtmlPathParsingTests { public void canReadSeparatorForElements() { assertThat( parseHtmlPath("p:separator('x')"), - deepEquals(HtmlPath.elements(HtmlPathElementBuilder.collapsible("p").separator("x").build())) + deepEquals(HtmlPath.elements(HtmlElementBuilder.collapsible("p").separator("x").pathElement())) ); } |
