blob: dc87945f167eb367bf6ca7f2c1c6ae802a765f3c (
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
|
package org.zwobble.mammoth.tests.styles;
import org.junit.Test;
import org.parboiled.support.Var;
import org.zwobble.mammoth.styles.ParagraphMatcher;
import org.zwobble.mammoth.styles.parsing.Parsing;
import org.zwobble.mammoth.styles.parsing.StyleMappingParser;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals;
public class DocumentMatcherParsingTests {
@Test
public void canReadPlainParagraph() {
assertThat(
parseParagraphMatcher("p"),
deepEquals(ParagraphMatcher.ANY));
}
@Test
public void readsParagraphWithStyleId() {
assertThat(
parseParagraphMatcher("p.Heading1"),
deepEquals(ParagraphMatcher.styleId("Heading1")));
}
@Test
public void readsParagraphWithStyleName() {
assertThat(
parseParagraphMatcher("p[style-name='Heading 1']"),
deepEquals(ParagraphMatcher.styleName("Heading 1")));
}
@Test
public void readsParagraphOrderedList() {
assertThat(
parseParagraphMatcher("p:ordered-list(2)"),
deepEquals(ParagraphMatcher.orderedList("1")));
}
@Test
public void readsParagraphUnorderedList() {
assertThat(
parseParagraphMatcher("p:unordered-list(2)"),
deepEquals(ParagraphMatcher.unorderedList("1")));
}
private ParagraphMatcher parseParagraphMatcher(String input) {
Var<ParagraphMatcher> matcher = new Var<>();
Parsing.parse(StyleMappingParser.class, parser -> parser.ParagraphMatcher(matcher), input);
return matcher.get();
}
}
|