aboutsummaryrefslogtreecommitdiff
path: root/src/test/java/org/zwobble/mammoth/tests/styles/HtmlPathParsingTests.java
blob: b2a44338a9ca5d23d3d084004fd840e65a2f5ee8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package org.zwobble.mammoth.tests.styles;

import org.junit.Test;
import org.zwobble.mammoth.styles.HtmlPath;
import org.zwobble.mammoth.styles.HtmlPathElement;
import org.zwobble.mammoth.styles.StyleMapParser;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals;
import static org.zwobble.mammoth.util.MammothLists.list;
import static org.zwobble.mammoth.util.MammothMaps.map;

public class HtmlPathParsingTests {
    @Test
    public void canParseEmptyPath() {
        assertThat(
            StyleMapParser.parseHtmlPath(""),
            deepEquals(HtmlPath.EMPTY));
    }

    @Test
    public void canReadSingleElement() {
        assertThat(
            StyleMapParser.parseHtmlPath("p"),
            deepEquals(HtmlPath.collapsibleElement("p")));
    }

    @Test
    public void canReadElementWithChoiceOfTagNames() {
        assertThat(
            StyleMapParser.parseHtmlPath("ul|ol"),
            deepEquals(HtmlPath.collapsibleElement(list("ul", "ol"))));

        assertThat(
            StyleMapParser.parseHtmlPath("ul|ol|p"),
            deepEquals(HtmlPath.collapsibleElement(list("ul", "ol", "p"))));
    }

    @Test
    public void canReadNestedElements() {
        assertThat(
            StyleMapParser.parseHtmlPath("ul > li"),
            deepEquals(new HtmlPath(list(HtmlPathElement.collapsible("ul"), HtmlPathElement.collapsible("li")))));
    }

    @Test
    public void canReadClassOnElement() {
        assertThat(
            StyleMapParser.parseHtmlPath("p.tip"),
            deepEquals(HtmlPath.collapsibleElement("p", map("class", "tip"))));
    }

    @Test
    public void canReadMultipleClassesOnElement() {
        assertThat(
            StyleMapParser.parseHtmlPath("p.tip.help"),
            deepEquals(HtmlPath.collapsibleElement("p", map("class", "tip help"))));
    }

    @Test
    public void canReadWhenElementMustBeFresh() {
        assertThat(
            StyleMapParser.parseHtmlPath("p:fresh"),
            deepEquals(HtmlPath.element("p")));
    }
}