-
Notifications
You must be signed in to change notification settings - Fork 241
Expand file tree
/
Copy pathStyleSpansBuilderTest.java
More file actions
70 lines (61 loc) · 2.33 KB
/
StyleSpansBuilderTest.java
File metadata and controls
70 lines (61 loc) · 2.33 KB
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
package org.fxmisc.richtext.model;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
import java.util.List;
import static org.fxmisc.richtext.model.StyleSpansChecker.checkStyle;
import static org.junit.jupiter.api.Assertions.assertThrows;
public class StyleSpansBuilderTest {
@Test
@DisplayName("Cannot create an empty style span")
void empty() {
assertThrows(IllegalStateException.class, () -> new StyleSpansBuilder<>().create());
}
@Test
@DisplayName("Creating a single-style style span")
void createStyleSpan() {
StyleSpans<String> style = new StyleSpansBuilder<String>().add("alpha", 10).create();
checkStyle(style, 10, new String[] {"alpha"}, 0, 10);
}
@Test
@DisplayName("Adding only empty styles")
void onlyEmptyStyles() {
StyleSpans<String> style = new StyleSpansBuilder<String>()
.add("alpha", 0)
.add("beta", 0)
.add("charlie", 0)
.create();
checkStyle(style, 0, new String[] {"alpha"}, 0, 0);
}
@Test
@DisplayName("Adding style on only empty, overwrites it")
void nonEmptyOnEmpty() {
StyleSpans<String> style = new StyleSpansBuilder<String>()
.add("alpha", 0)
.add("beta", 0)
.add("charlie", 0)
.add("delta", 1)
.create();
checkStyle(style, 1, new String[] {"delta"}, 0, 1);
}
@Test
@DisplayName("Add a list of only one style will merge them all")
void addListOfOneStyle() {
StyleSpans<String> style = new StyleSpansBuilder<String>()
.addAll(List.of(new StyleSpan<>("alpha", 1), new StyleSpan<>("alpha", 2), new StyleSpan<>("alpha", 3)))
.create();
checkStyle(style, 6, new String[] {"alpha"}, 0, 6);
}
@Test
@DisplayName("Creating a multi-style style span")
void multiStyleSpan() {
StyleSpans<String> style = new StyleSpansBuilder<String>()
.add("alpha", 1)
.add("alpha", 2)
.add("beta", 3)
.add("delta", 0)
.add("charlie", 4)
.add("alpha", 5)
.create();
checkStyle(style, 15, new String[] {"alpha", "beta", "charlie", "alpha"}, 0, 3, 3, 6, 6, 10, 10, 15);
}
}