Skip to content

Commit

Permalink
Add highlight matcher
Browse files Browse the repository at this point in the history
  • Loading branch information
mwilliamson committed Jun 13, 2024
1 parent 326d351 commit bb5735e
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -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);
}
}
Original file line number Diff line number Diff line change
@@ -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));
}
}

0 comments on commit bb5735e

Please sign in to comment.