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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
|
package org.zwobble.mammoth.tests.styles.parsing;
import org.junit.jupiter.api.Test;
import org.zwobble.mammoth.internal.styles.*;
import org.zwobble.mammoth.internal.styles.parsing.StyleMapParser;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.zwobble.mammoth.tests.DeepReflectionMatcher.deepEquals;
public class StyleMapParserTests {
@Test
public void emptyStringIsParsedAsEmptyStyleMap() {
StyleMap styleMap = StyleMapParser.parse("");
assertThat(styleMap, deepEquals(StyleMap.builder().build()));
}
@Test
public void canMapParagraphs() {
StyleMap styleMap = StyleMapParser.parse("p => p");
assertThat(styleMap, deepEquals(StyleMap.builder().mapParagraph(ParagraphMatcher.ANY, HtmlPath.collapsibleElement("p")).build()));
}
@Test
public void canMapRuns() {
StyleMap styleMap = StyleMapParser.parse("r => p");
assertThat(styleMap, deepEquals(StyleMap.builder().mapRun(RunMatcher.ANY, HtmlPath.collapsibleElement("p")).build()));
}
@Test
public void canMapBold() {
StyleMap styleMap = StyleMapParser.parse("b => em");
assertThat(styleMap, deepEquals(StyleMap.builder().bold(HtmlPath.collapsibleElement("em")).build()));
}
@Test
public void canMapItalic() {
StyleMap styleMap = StyleMapParser.parse("i => strong");
assertThat(styleMap, deepEquals(StyleMap.builder().italic(HtmlPath.collapsibleElement("strong")).build()));
}
@Test
public void canMapUnderline() {
StyleMap styleMap = StyleMapParser.parse("u => em");
assertThat(styleMap, deepEquals(StyleMap.builder().underline(HtmlPath.collapsibleElement("em")).build()));
}
@Test
public void canMapStrikethrough() {
StyleMap styleMap = StyleMapParser.parse("strike => del");
assertThat(styleMap, deepEquals(StyleMap.builder().strikethrough(HtmlPath.collapsibleElement("del")).build()));
}
@Test
public void canMapAllCaps() {
StyleMap styleMap = StyleMapParser.parse("all-caps => span");
assertThat(styleMap, deepEquals(StyleMap.builder().allCaps(HtmlPath.collapsibleElement("span")).build()));
}
@Test
public void canMapSmallCaps() {
StyleMap styleMap = StyleMapParser.parse("small-caps => span");
assertThat(styleMap, deepEquals(StyleMap.builder().smallCaps(HtmlPath.collapsibleElement("span")).build()));
}
@Test
public void canMapCommentReference() {
StyleMap styleMap = StyleMapParser.parse("comment-reference =>");
assertThat(styleMap, deepEquals(StyleMap.builder().commentReference(HtmlPath.EMPTY).build()));
}
@Test
public void canMapLineBreaks() {
StyleMap styleMap = StyleMapParser.parse("br[type='line'] => div");
StyleMap expectedStyleMap = StyleMap.builder()
.mapBreak(BreakMatcher.LINE_BREAK, HtmlPath.collapsibleElement("div"))
.build();
assertThat(styleMap, deepEquals(expectedStyleMap));
}
@Test
public void canMapPageBreaks() {
StyleMap styleMap = StyleMapParser.parse("br[type='page'] => div");
StyleMap expectedStyleMap = StyleMap.builder()
.mapBreak(BreakMatcher.PAGE_BREAK, HtmlPath.collapsibleElement("div"))
.build();
assertThat(styleMap, deepEquals(expectedStyleMap));
}
@Test
public void canMapColumnBreaks() {
StyleMap styleMap = StyleMapParser.parse("br[type='column'] => div");
StyleMap expectedStyleMap = StyleMap.builder()
.mapBreak(BreakMatcher.COLUMN_BREAK, HtmlPath.collapsibleElement("div"))
.build();
assertThat(styleMap, deepEquals(expectedStyleMap));
}
@Test
public void blankLinesAreIgnored() {
StyleMap styleMap = StyleMapParser.parse("\n\n \n\np =>\n\r\n");
assertThat(styleMap, deepEquals(StyleMap.builder().mapParagraph(ParagraphMatcher.ANY, HtmlPath.EMPTY).build()));
}
@Test
public void lineStartingWithHashIsIgnored() {
StyleMap styleMap = StyleMapParser.parse("#p => p");
assertThat(styleMap, deepEquals(StyleMap.EMPTY));
}
@Test
public void canParseMultipleMappings() {
StyleMap styleMap = StyleMapParser.parse("p =>\nr =>");
assertThat(styleMap, deepEquals(StyleMap.builder()
.mapParagraph(ParagraphMatcher.ANY, HtmlPath.EMPTY)
.mapRun(RunMatcher.ANY, HtmlPath.EMPTY)
.build()));
}
}
|