diff --git a/src/main/java/walkingkooka/spreadsheet/expression/function/TextMatch.java b/src/main/java/walkingkooka/spreadsheet/expression/function/TextMatch.java index 22a091c..ecda067 100644 --- a/src/main/java/walkingkooka/spreadsheet/expression/function/TextMatch.java +++ b/src/main/java/walkingkooka/spreadsheet/expression/function/TextMatch.java @@ -17,6 +17,7 @@ package walkingkooka.spreadsheet.expression.function; +import walkingkooka.CanBeEmpty; import walkingkooka.Value; import walkingkooka.predicate.Predicates; import walkingkooka.text.CaseSensitivity; @@ -30,7 +31,8 @@ */ public final class TextMatch implements Value, Predicate, - HasCaseSensitivity { + HasCaseSensitivity, + CanBeEmpty { public static TextMatch parse(final String text) { Objects.requireNonNull(text, "text"); @@ -65,6 +67,17 @@ public CaseSensitivity caseSensitivity() { private final static CaseSensitivity CASE_SENSITIVITY = CaseSensitivity.INSENSITIVE; + // CanBeEmpty....................................................................................................... + + /** + * A {@link TextMatch} is empty if it is only whitespace and has no actual glob pattern(s). + */ + @Override + public boolean isEmpty() { + return this.text.trim() + .isEmpty(); + } + // Predicate........................................................................................................ @Override diff --git a/src/test/java/walkingkooka/spreadsheet/expression/function/TextMatchTest.java b/src/test/java/walkingkooka/spreadsheet/expression/function/TextMatchTest.java index ad09f3d..5a90f9d 100644 --- a/src/test/java/walkingkooka/spreadsheet/expression/function/TextMatchTest.java +++ b/src/test/java/walkingkooka/spreadsheet/expression/function/TextMatchTest.java @@ -18,6 +18,7 @@ package walkingkooka.spreadsheet.expression.function; import org.junit.jupiter.api.Test; +import walkingkooka.CanBeEmptyTesting; import walkingkooka.HashCodeEqualsDefinedTesting2; import walkingkooka.predicate.PredicateTesting2; import walkingkooka.test.ParseStringTesting; @@ -26,7 +27,8 @@ public final class TextMatchTest implements ParseStringTesting, PredicateTesting2, - HashCodeEqualsDefinedTesting2 { + HashCodeEqualsDefinedTesting2, + CanBeEmptyTesting { // with............................................................................................................. @@ -77,6 +79,56 @@ public RuntimeException parseStringFailedExpected(final RuntimeException thrown) return thrown; } + // isEmpty.......................................................................................................... + + @Test + public void testIsEmptyWhenEmptyString() { + this.isEmptyAndCheck( + "", + true + ); + } + + @Test + public void testIsEmptyWhenNotEmptyWhitespaceOnlyString() { + this.isEmptyAndCheck( + " ", + true + ); + } + + @Test + public void testIsEmptyWhenNotEmptyWhitespaceOnlyString2() { + this.isEmptyAndCheck( + " ", + true + ); + } + + @Test + public void testIsEmptyWhenOneGlobPattern() { + this.isEmptyAndCheck( + "*", + false + ); + } + + @Test + public void testIsEmptyWhenSeveralGlobPatterns() { + this.isEmptyAndCheck( + "1 2* ?3", + false + ); + } + + private void isEmptyAndCheck(final String text, + final boolean expected) { + this.isEmptyAndCheck( + this.parseString(text), + expected + ); + } + // Predicate........................................................................................................ @Test