summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2024-06-13 12:26:22 +0100
committerMichael Williamson <mike@zwobble.org>2024-06-13 12:26:22 +0100
commitbb5735ea0f145e83ade533ddd18bfb2dc6e25759 (patch)
tree6627206a12cc1792e5f100724c506b3bdb1b8122
parent326d3519ff7d92c2434b07b6ca615ec7819d8103 (diff)
Add highlight matcher
-rw-r--r--src/main/java/org/zwobble/mammoth/internal/styles/HighlightMatcher.java16
-rw-r--r--src/test/java/org/zwobble/mammoth/tests/styles/HighlightMatcherTests.java38
2 files changed, 54 insertions, 0 deletions
diff --git a/src/main/java/org/zwobble/mammoth/internal/styles/HighlightMatcher.java b/src/main/java/org/zwobble/mammoth/internal/styles/HighlightMatcher.java
new file mode 100644
index 0000000..2e0481b
--- /dev/null
+++ b/src/main/java/org/zwobble/mammoth/internal/styles/HighlightMatcher.java
@@ -0,0 +1,16 @@
+package org.zwobble.mammoth.internal.styles;
+
+import java.util.Optional;
+
+public class HighlightMatcher implements DocumentElementMatcher<String> {
+ private final Optional<String> color;
+
+ public HighlightMatcher(Optional<String> color) {
+ this.color = color;
+ }
+
+ @Override
+ public boolean matches(String color) {
+ return !this.color.isPresent() || this.color.get().equals(color);
+ }
+}
diff --git a/src/test/java/org/zwobble/mammoth/tests/styles/HighlightMatcherTests.java b/src/test/java/org/zwobble/mammoth/tests/styles/HighlightMatcherTests.java
new file mode 100644
index 0000000..4714f9a
--- /dev/null
+++ b/src/test/java/org/zwobble/mammoth/tests/styles/HighlightMatcherTests.java
@@ -0,0 +1,38 @@
+package org.zwobble.mammoth.tests.styles;
+
+import org.junit.jupiter.api.Test;
+import org.zwobble.mammoth.internal.styles.HighlightMatcher;
+
+import java.util.Optional;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
+
+public class HighlightMatcherTests {
+ @Test
+ public void highlightMatcherWithoutColorMatchesAllHighlightElements() {
+ HighlightMatcher matcher = new HighlightMatcher(Optional.empty());
+
+ boolean result = matcher.matches("yellow");
+
+ assertThat(result, equalTo(true));
+ }
+
+ @Test
+ public void highlightMatcherWithColorMatchesHighlightWithThatColor() {
+ HighlightMatcher matcher = new HighlightMatcher(Optional.of("yellow"));
+
+ boolean result = matcher.matches("yellow");
+
+ assertThat(result, equalTo(true));
+ }
+
+ @Test
+ public void highlightMatcherWithColorDoesNotMatchHighlightsWithOtherColors() {
+ HighlightMatcher matcher = new HighlightMatcher(Optional.of("yellow"));
+
+ boolean result = matcher.matches("red");
+
+ assertThat(result, equalTo(false));
+ }
+}