Skip to content

Commit

Permalink
Merge pull request #195 from mP1/feature/TextMatch-implements-CanBeEmpty
Browse files Browse the repository at this point in the history
TextMatch implements CanBeEmpty
  • Loading branch information
mP1 authored Nov 12, 2024
2 parents 67de421 + c27c327 commit 2e22dcf
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

package walkingkooka.spreadsheet.expression.function;

import walkingkooka.CanBeEmpty;
import walkingkooka.Value;
import walkingkooka.predicate.Predicates;
import walkingkooka.text.CaseSensitivity;
Expand All @@ -30,7 +31,8 @@
*/
public final class TextMatch implements Value<String>,
Predicate<CharSequence>,
HasCaseSensitivity {
HasCaseSensitivity,
CanBeEmpty {

public static TextMatch parse(final String text) {
Objects.requireNonNull(text, "text");
Expand Down Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -26,7 +27,8 @@

public final class TextMatchTest implements ParseStringTesting<TextMatch>,
PredicateTesting2<TextMatch, CharSequence>,
HashCodeEqualsDefinedTesting2<TextMatch> {
HashCodeEqualsDefinedTesting2<TextMatch>,
CanBeEmptyTesting {

// with.............................................................................................................

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 2e22dcf

Please sign in to comment.