toCapture;
private final int numCapturingPlaceholders;
- private final CharPredicate requiredChars; // null for unconstrained matches
-
- /**
- * Returns a strict StringFormat according to the {@code format} string. All placeholder values
- * must be non-empty and all placeholder value characters must match {@code
- * requiredChars}.
- *
- * For example:
- *
- *
{@code
- * StringFormat userFormat =
- * StringFormat.strict("user: {user_id}", CharMatcher.inRange('0', '9'));
- * userFormat.parse("user: 123", id -> Integer.parseInt(id)) => Optional.of(123)
- * userFormat.parse("user: xyz", ...) => empty()
- * userFormat.parse("user: ", ...) => empty()
- * }
- *
- * Note that {@code requiredChars} applies to all placeholders. If you need to apply
- * constraints on an individual placeholder, consider filtering in the lambda by returning null if
- * the placeholder value isn't valid.
- *
- *
Parameters passed to {@link #format} are not checked so it's possible that {@code format()}
- * returns a string not parseable by the same {@code StringFormat} strict instance.
- *
- * @since 6.7
- * @deprecated Consider manually checking the placeholder values in the lambda
- */
- @Deprecated
- public static StringFormat strict(String format, CharPredicate requiredChars) {
- return new StringFormat(format, requireNonNull(requiredChars));
- }
/**
* Returns a {@link Substring.Pattern} spanning the substring matching {@code format}. For
@@ -258,10 +227,6 @@ public String toString() {
* (e.g. a placeholder immediately followed by another placeholder)
*/
public StringFormat(String format) {
- this(format, null);
- }
-
- private StringFormat(String format, CharPredicate requiredChars) {
Stream.Builder delimiters = Stream.builder();
Stream.Builder toCapture = Stream.builder();
PLACEHOLDERS.split(format).forEachOrdered(
@@ -274,7 +239,6 @@ private StringFormat(String format, CharPredicate requiredChars) {
this.toCapture = chop(toCapture.build().collect(toImmutableList()));
this.numCapturingPlaceholders =
this.fragments.size() - 1 - (int) this.toCapture.stream().filter(c -> !c).count();
- this.requiredChars = requiredChars;
}
/**
@@ -394,9 +358,6 @@ private Optional> internalParse(
if (placeholder == null) {
return Optional.empty();
}
- if (requiredChars != null && !isValidPlaceholderValue(placeholder)) {
- return Optional.empty();
- }
if (toCapture.get(i - 1)) {
builder.add(placeholder);
}
@@ -671,17 +632,17 @@ public boolean matches(String input) {
public Stream> scan(String input) {
requireNonNull(input);
if (format.isEmpty()) {
- return requiredChars == null
- ? Stream.generate(() -> Collections.emptyList()).limit(input.length() + 1)
- : Stream.empty();
+ return Stream.generate(() -> Collections.emptyList())
+ .limit(input.length() + 1);
}
int numPlaceholders = numPlaceholders();
- Stream> groups = MoreStreams.whileNotNull(
+ return MoreStreams.whileNotNull(
new Supplier>() {
private int inputIndex = 0;
private boolean done = false;
- @Override public List get() {
+ @Override
+ public List get() {
if (done) {
return null;
}
@@ -713,10 +674,6 @@ public Stream> scan(String input) {
return unmodifiableList(builder);
}
});
- if (requiredChars == null) {
- return groups;
- }
- return groups.filter(matches -> matches.stream().allMatch(this::isValidPlaceholderValue));
}
/**
@@ -996,9 +953,6 @@ private void checkPlaceholderCount(int expected) {
}
}
- private boolean isValidPlaceholderValue(CharSequence chars) {
- return requiredChars == null || (chars.length() > 0 && requiredChars.matchesAllOf(chars));
- }
private void checkFormatArgs(Object[] args) {
if (args.length != numPlaceholders()) {
diff --git a/mug/src/test/java/com/google/mu/util/StringFormatTest.java b/mug/src/test/java/com/google/mu/util/StringFormatTest.java
index 5eb22317e0..cbb39c60d7 100644
--- a/mug/src/test/java/com/google/mu/util/StringFormatTest.java
+++ b/mug/src/test/java/com/google/mu/util/StringFormatTest.java
@@ -19,54 +19,51 @@
import com.google.common.truth.OptionalSubject;
import com.google.errorprone.annotations.CompileTimeConstant;
import com.google.mu.util.stream.BiStream;
-import com.google.testing.junit.testparameterinjector.TestParameter;
import com.google.testing.junit.testparameterinjector.TestParameterInjector;
@RunWith(TestParameterInjector.class)
public class StringFormatTest {
- private static final CharPredicate DIGIT = CharPredicate.range('0', '9');
-
@Test
- public void parse_noPlaceholder(@TestParameter Mode mode) {
- StringFormat format = mode.formatOf("this is literal");
+ public void parse_noPlaceholder() {
+ StringFormat format = new StringFormat("this is literal");
assertThat(format.parse("this is literal").get()).isEmpty();
}
@Test
- public void parse_emptyCurlyBrace_doesNotCountAsPlaceholder(@TestParameter Mode mode) {
- StringFormat format = mode.formatOf("curly brace: {}");
+ public void parse_emptyCurlyBrace_doesNotCountAsPlaceholder() {
+ StringFormat format = new StringFormat("curly brace: {}");
assertThat(format.parse("curly brace: {}").get()).isEmpty();
}
@Test
- public void parse_onlyPlaceholder(@TestParameter Mode mode) {
- StringFormat format = mode.formatOf("{v}");
+ public void parse_onlyPlaceholder() {
+ StringFormat format = new StringFormat("{v}");
assertThat(format.parse("Hello Tom!", v -> v)).hasValue("Hello Tom!");
assertThat(format.parseOrThrow("Hello Tom!", (String v) -> v)).isEqualTo("Hello Tom!");
}
@Test
- public void parse_onlyEllipsis(@TestParameter Mode mode) {
- StringFormat format = mode.formatOf("{...}");
+ public void parse_onlyEllipsis() {
+ StringFormat format = new StringFormat("{...}");
assertThat(format.parse("Hello Tom!")).hasValue(ImmutableList.of());
}
@Test
- public void parse_singlePlaceholder(@TestParameter Mode mode) {
- StringFormat format = mode.formatOf("Hello {v}!");
+ public void parse_singlePlaceholder() {
+ StringFormat format = new StringFormat("Hello {v}!");
assertThat(format.parse("Hello Tom!", v -> v)).hasValue("Tom");
assertThat(format.parseOrThrow("Hello Tom!", (String v) -> v)).isEqualTo("Tom");
}
@Test
- public void parse_singlePlaceholder_withEllipsis(@TestParameter Mode mode) {
- StringFormat format = mode.formatOf("Hello {...}!");
+ public void parse_singlePlaceholder_withEllipsis() {
+ StringFormat format = new StringFormat("Hello {...}!");
assertThat(format.parse("Hello Tom!")).hasValue(ImmutableList.of());
}
@Test
- public void parse_multiplePlaceholders(@TestParameter Mode mode) {
- StringFormat format = mode.formatOf("Hello {person}, welcome to {place}!");
+ public void parse_multiplePlaceholders() {
+ StringFormat format = new StringFormat("Hello {person}, welcome to {place}!");
assertThat(
format.parse("Hello Gandolf, welcome to Isengard!").get().stream()
.map(Object::toString))
@@ -75,8 +72,8 @@ public void parse_multiplePlaceholders(@TestParameter Mode mode) {
}
@Test
- public void parse_multiplePlaceholders_withEllipsis(@TestParameter Mode mode) {
- StringFormat format = mode.formatOf("Hello {...}, welcome to {place}!");
+ public void parse_multiplePlaceholders_withEllipsis() {
+ StringFormat format = new StringFormat("Hello {...}, welcome to {place}!");
assertThat(
format.parse("Hello Gandolf, welcome to Isengard!").get().stream()
.map(Object::toString))
@@ -84,16 +81,16 @@ public void parse_multiplePlaceholders_withEllipsis(@TestParameter Mode mode) {
}
@Test
- public void parse_multiplePlaceholders_withEllipsis_usingLambda(@TestParameter Mode mode) {
- StringFormat format = mode.formatOf("Hello {...}, welcome to {place}!");
+ public void parse_multiplePlaceholders_withEllipsis_usingLambda() {
+ StringFormat format = new StringFormat("Hello {...}, welcome to {place}!");
assertThat(format.parse("Hello Gandolf, welcome to Isengard!", p -> p)).hasValue("Isengard");
assertThat(format.parseOrThrow("Hello Gandolf, welcome to Isengard!", (String p) -> p))
.isEqualTo("Isengard");
}
@Test
- public void parse_multiplePlaceholdersWithSameName(@TestParameter Mode mode) {
- StringFormat format = mode.formatOf("Hello {name} and {name}!");
+ public void parse_multiplePlaceholdersWithSameName() {
+ StringFormat format = new StringFormat("Hello {name} and {name}!");
assertThat(format.parse("Hello Gandolf and Aragon!").get().stream().map(Object::toString))
.containsExactly("Gandolf", "Aragon")
.inOrder();
@@ -107,114 +104,101 @@ public void parse_emptyPlaceholderValue() {
}
@Test
- public void parse_strict_emptyPlaceholderValue() {
- StringFormat format = Mode.NO_EMPTY_MATCH.formatOf("Hello {what}!");
- assertThat(format.parse("Hello !")).isEmpty();
- }
-
- @Test
- public void parse_strict_placeholdeWithInvalidChar() {
- StringFormat format = StringFormat.strict("Hello {what}!", DIGIT);
- assertThat(format.parse("Hello x!")).isEmpty();
- assertThat(format.parse("Hello x1!")).isEmpty();
- assertThat(format.parse("Hello 1x!")).isEmpty();
- }
-
- @Test
- public void parse_preludeFailsToMatch(@TestParameter Mode mode) {
- StringFormat format = mode.formatOf("Hello {person}!");
+ public void parse_preludeFailsToMatch() {
+ StringFormat format = new StringFormat("Hello {person}!");
assertThat(format.parse("Hell Tom!")).isEmpty();
assertThat(format.parse("elloh Tom!")).isEmpty();
assertThat(format.parse(" Hello Tom!")).isEmpty();
}
@Test
- public void parse_postludeFailsToMatch(@TestParameter Mode mode) {
- StringFormat format = mode.formatOf("Hello {person}!");
+ public void parse_postludeFailsToMatch() {
+ StringFormat format = new StringFormat("Hello {person}!");
assertThat(format.parse("Hello Tom?")).isEmpty();
assertThat(format.parse("Hello Tom! ")).isEmpty();
assertThat(format.parse("Hello Tom")).isEmpty();
}
@Test
- public void parse_nonEmptyTemplate_emptyInput(@TestParameter Mode mode) {
- StringFormat format = mode.formatOf("Hello {person}!");
+ public void parse_nonEmptyTemplate_emptyInput() {
+ StringFormat format = new StringFormat("Hello {person}!");
assertThat(format.parse("")).isEmpty();
}
@Test
- public void parse_emptyTemplate_nonEmptyInput(@TestParameter Mode mode) {
- assertThat(mode.formatOf("").parse(".")).isEmpty();
+ public void parse_emptyTemplate_nonEmptyInput() {
+ assertThat(new StringFormat("").parse(".")).isEmpty();
}
@Test
- public void parse_emptyTemplate_emptyInput(@TestParameter Mode mode) {
- assertThat(mode.formatOf("").parse("")).hasValue(ImmutableList.of());
+ public void parse_emptyTemplate_emptyInput() {
+ assertThat(new StringFormat("").parse("")).hasValue(ImmutableList.of());
}
@Test
- public void parse_withOneArgLambda(@TestParameter Mode mode) {
- assertThat(mode.formatOf("1 is {what}").parse("1 is one", Object::toString)).hasValue("one");
+ public void parse_withOneArgLambda() {
+ assertThat(new StringFormat("1 is {what}").parse("1 is one", Object::toString)).hasValue("one");
}
@Test
- public void parse_withOneArgLambda_emptyInput(@TestParameter Mode mode) {
- assertThat(mode.formatOf("1 is {what}").parse("", Object::toString)).isEmpty();
+ public void parse_withOneArgLambda_emptyInput() {
+ assertThat(new StringFormat("1 is {what}").parse("", Object::toString)).isEmpty();
}
@Test
- public void parse_withOneArgLambda_lambdaReturnsNull(@TestParameter Mode mode) {
- assertThat(mode.formatOf("1 is {what}").parse("1 is one", w -> null)).isEmpty();
+ public void parse_withOneArgLambda_lambdaReturnsNull() {
+ assertThat(new StringFormat("1 is {what}").parse("1 is one", w -> null)).isEmpty();
NullPointerException thrown =
assertThrows(
NullPointerException.class,
- () -> mode.formatOf("1 is {what}").parseOrThrow("1 is one", w -> null));
+ () -> new StringFormat("1 is {what}").parseOrThrow("1 is one", w -> null));
assertThat(thrown).hasMessageThat().contains("format string '1 is {what}'");
assertThat(thrown).hasMessageThat().contains("input '1 is one'");
}
@Test
- public void parse_withTwoArgsLambda(@TestParameter Mode mode) {
+ public void parse_withTwoArgsLambda() {
assertThat(
- mode.formatOf("1 is {what}, 2 is {what}").parse("1 is one, 2 is two", String::concat))
+ new StringFormat("1 is {what}, 2 is {what}")
+ .parse("1 is one, 2 is two", String::concat))
.hasValue("onetwo");
assertThat(
- mode.formatOf("1 is {what}, 2 is {what}")
+ new StringFormat("1 is {what}, 2 is {what}")
.parseOrThrow("1 is one, 2 is two", String::concat))
.isEqualTo("onetwo");
}
@Test
- public void parse_withTwoArgsLambda_emptyInput(@TestParameter Mode mode) {
- assertThat(mode.formatOf("1 is {x}, 2 is {y}").parse("", (x, y) -> null)).isEmpty();
+ public void parse_withTwoArgsLambda_emptyInput() {
+ assertThat(new StringFormat("1 is {x}, 2 is {y}").parse("", (x, y) -> null)).isEmpty();
IllegalArgumentException thrown =
assertThrows(
IllegalArgumentException.class,
- () -> mode.formatOf("1 is {x}, 2 is {y}").parseOrThrow("", (x, y) -> null));
+ () -> new StringFormat("1 is {x}, 2 is {y}").parseOrThrow("", (x, y) -> null));
}
@Test
- public void parse_withTwoArgsLambda_lambdaReturnsNull(@TestParameter Mode mode) {
- assertThat(mode.formatOf("1 is {x}, 2 is {y}").parse("1 is one, 2 is two", (x, y) -> null))
+ public void parse_withTwoArgsLambda_lambdaReturnsNull() {
+ assertThat(new StringFormat("1 is {x}, 2 is {y}").parse("1 is one, 2 is two", (x, y) -> null))
.isEmpty();
NullPointerException thrown =
assertThrows(
NullPointerException.class,
() ->
- mode.formatOf("1 is {x}, 2 is {y}")
+ new StringFormat("1 is {x}, 2 is {y}")
.parseOrThrow("1 is one, 2 is two", (x, y) -> null));
assertThat(thrown).hasMessageThat().contains("format string '1 is {x}, 2 is {y}'");
assertThat(thrown).hasMessageThat().contains("input '1 is one, 2 is two'");
}
@Test
- public void parse_withThreeArgsLambda(@TestParameter Mode mode) {
+ public void parse_withThreeArgsLambda() {
assertThat(
- mode.formatOf("1 is {x}, 2 is {y}, 3 is {z}")
+ new StringFormat("1 is {x}, 2 is {y}, 3 is {z}")
.parse("1 is one, 2 is two, 3 is three", (x, y, z) -> x + "," + y + "," + z))
.hasValue("one,two,three");
assertThat(
- mode.formatOf("1 is {x}, 2 is {y}, 3 is {z}")
+ new StringFormat("1 is {x}, 2 is {y}, 3 is {z}")
.parseOrThrow(
"1 is one, 2 is two, 3 is three",
(String x, String y, String z) -> x + "," + y + "," + z))
@@ -222,35 +206,35 @@ public void parse_withThreeArgsLambda(@TestParameter Mode mode) {
}
@Test
- public void parse_withThreeArgsLambda_emptyInput(@TestParameter Mode mode) {
- assertThat(mode.formatOf("1 is {x}, 2 is {y}, 3 is {z}").parse("", (x, y, z) -> null))
+ public void parse_withThreeArgsLambda_emptyInput() {
+ assertThat(new StringFormat("1 is {x}, 2 is {y}, 3 is {z}").parse("", (x, y, z) -> null))
.isEmpty();
assertThrows(
IllegalArgumentException.class,
- () -> mode.formatOf("1 is {x}, 2 is {y}, 3 is {z}").parseOrThrow("", (x, y, z) -> null));
+ () -> new StringFormat("1 is {x}, 2 is {y}, 3 is {z}").parseOrThrow("", (x, y, z) -> null));
}
@Test
- public void parse_withThreeArgsLambda_lambdaReturnsNull(@TestParameter Mode mode) {
+ public void parse_withThreeArgsLambda_lambdaReturnsNull() {
assertThat(
- mode.formatOf("1 is {x}, 2 is {y}, 3 is {z}")
+ new StringFormat("1 is {x}, 2 is {y}, 3 is {z}")
.parse("1 is one, 2 is two, 3 is three", (x, y, z) -> null))
.isEmpty();
assertThrows(
NullPointerException.class,
() ->
- mode.formatOf("1 is {x}, 2 is {y}, 3 is {z}")
+ new StringFormat("1 is {x}, 2 is {y}, 3 is {z}")
.parseOrThrow("1 is one, 2 is two, 3 is three", (x, y, z) -> null));
}
@Test
- public void parse_withFourArgsLambda(@TestParameter Mode mode) {
+ public void parse_withFourArgsLambda() {
assertThat(
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}")
.parse("1 is one, 2 is two, 3 is three, 4 is four", (a, b, c, d) -> a + b + c + d))
.hasValue("onetwothreefour");
assertThat(
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}")
.parseOrThrow(
"1 is one, 2 is two, 3 is three, 4 is four",
(String a, String b, String c, String d) -> a + b + c + d))
@@ -258,40 +242,41 @@ public void parse_withFourArgsLambda(@TestParameter Mode mode) {
}
@Test
- public void parse_withFourArgsLambda_emptyInput(@TestParameter Mode mode) {
+ public void parse_withFourArgsLambda_emptyInput() {
assertThat(
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}").parse("", (a, b, c, d) -> null))
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}")
+ .parse("", (a, b, c, d) -> null))
.isEmpty();
assertThrows(
IllegalArgumentException.class,
() ->
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}")
.parseOrThrow("", (a, b, c, d) -> null));
}
@Test
- public void parse_withFourArgsLambda_lambdaReturnsNull(@TestParameter Mode mode) {
+ public void parse_withFourArgsLambda_lambdaReturnsNull() {
assertThat(
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}")
.parse("1 is one, 2 is two, 3 is three, 4 is four", (a, b, c, d) -> null))
.isEmpty();
assertThrows(
NullPointerException.class,
() ->
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}")
.parseOrThrow("1 is one, 2 is two, 3 is three, 4 is four", (a, b, c, d) -> null));
}
@Test
- public void parse_withFiveArgsLambda(@TestParameter Mode mode) {
+ public void parse_withFiveArgsLambda() {
assertThat(
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}")
.parse(
"1 is one, 2 is two, 3 is three, 4 is four, 5 is five",
(a, b, c, d, e) -> a + b + c + d + e))
.hasValue("onetwothreefourfive");
assertThat(
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}")
.parseOrThrow(
"1 is one, 2 is two, 3 is three, 4 is four, 5 is five",
(String a, String b, String c, String d, String e) -> a + b + c + d + e))
@@ -299,22 +284,22 @@ public void parse_withFiveArgsLambda(@TestParameter Mode mode) {
}
@Test
- public void parse_withFiveArgsLambda_emptyInput(@TestParameter Mode mode) {
+ public void parse_withFiveArgsLambda_emptyInput() {
assertThat(
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}")
.parse("", (a, b, c, d, e) -> null))
.isEmpty();
assertThrows(
IllegalArgumentException.class,
() ->
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}")
.parseOrThrow("", (a, b, c, d, e) -> null));
}
@Test
- public void parse_withFiveArgsLambda_lambdaReturnsNull(@TestParameter Mode mode) {
+ public void parse_withFiveArgsLambda_lambdaReturnsNull() {
assertThat(
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}")
.parse(
"1 is one, 2 is two, 3 is three, 4 is four, 5 is five",
(a, b, c, d, e) -> null))
@@ -322,22 +307,22 @@ public void parse_withFiveArgsLambda_lambdaReturnsNull(@TestParameter Mode mode)
assertThrows(
NullPointerException.class,
() ->
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}")
.parseOrThrow(
"1 is one, 2 is two, 3 is three, 4 is four, 5 is five",
(a, b, c, d, e) -> null));
}
@Test
- public void parse_withSixArgsLambda(@TestParameter Mode mode) {
+ public void parse_withSixArgsLambda() {
assertThat(
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}, 6 is {f}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}, 6 is {f}")
.parse(
"1 is one, 2 is two, 3 is three, 4 is four, 5 is five, 6 is six",
(a, b, c, d, e, f) -> a + b + c + d + e + f))
.hasValue("onetwothreefourfivesix");
assertThat(
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}, 6 is {f}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}, 6 is {f}")
.parseOrThrow(
"1 is one, 2 is two, 3 is three, 4 is four, 5 is five, 6 is six",
(a, b, c, d, e, f) -> a + b + c + d + e + f))
@@ -345,22 +330,22 @@ public void parse_withSixArgsLambda(@TestParameter Mode mode) {
}
@Test
- public void parse_withSixArgsLambda_emptyInput(@TestParameter Mode mode) {
+ public void parse_withSixArgsLambda_emptyInput() {
assertThat(
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}, 6 is {f}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}, 6 is {f}")
.parse("", (a, b, c, d, e, f) -> null))
.isEmpty();
assertThrows(
IllegalArgumentException.class,
() ->
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}, 6 is {f}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}, 6 is {f}")
.parseOrThrow("", (a, b, c, d, e, f) -> null));
}
@Test
- public void parse_withSixArgsLambda_lambdaReturnsNull(@TestParameter Mode mode) {
+ public void parse_withSixArgsLambda_lambdaReturnsNull() {
assertThat(
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}, 6 is {f}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}, 6 is {f}")
.parse(
"1 is one, 2 is two, 3 is three, 4 is four, 5 is five, 6 is six",
(a, b, c, d, e, f) -> null))
@@ -368,66 +353,66 @@ public void parse_withSixArgsLambda_lambdaReturnsNull(@TestParameter Mode mode)
assertThrows(
NullPointerException.class,
() ->
- mode.formatOf("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}, 6 is {f}")
+ new StringFormat("1 is {a}, 2 is {b}, 3 is {c}, 4 is {d}, 5 is {e}, 6 is {f}")
.parseOrThrow(
"1 is one, 2 is two, 3 is three, 4 is four, 5 is five, 6 is six",
(a, b, c, d, e, f) -> null));
}
@Test
- public void parse_placeholderInsideCurlyBraces(@TestParameter Mode mode) {
- StringFormat format = mode.formatOf("{key={key}, value={value}}");
+ public void parse_placeholderInsideCurlyBraces() {
+ StringFormat format = new StringFormat("{key={key}, value={value}}");
assertThat(format.parse("{key=one, value=1}", (key, value) -> key + ":" + value))
.hasValue("one:1");
}
@Test
- public void parse_multipleCurlyBracedPlaceholderGroups(@TestParameter Mode mode) {
- StringFormat format = mode.formatOf("{key={key}}{value={value}}");
+ public void parse_multipleCurlyBracedPlaceholderGroups() {
+ StringFormat format = new StringFormat("{key={key}}{value={value}}");
assertThat(format.parse("{key=one}{value=1}", (key, value) -> key + ":" + value))
.hasValue("one:1");
}
@Test
@SuppressWarnings("StringFormatArgsCheck")
- public void parse_placeholderInsideMultipleCurlyBraces(@TestParameter Mode mode) {
- StringFormat format = mode.formatOf("{test: {{key={key}, value={value}}}}");
+ public void parse_placeholderInsideMultipleCurlyBraces() {
+ StringFormat format = new StringFormat("{test: {{key={key}, value={value}}}}");
assertThat(format.parse("{test: {{key=one, value=1}}}", (key, value) -> key + ":" + value))
.hasValue("one:1");
}
@Test
@SuppressWarnings("StringUnformatArgsCheck")
- public void twoPlaceholdersNextToEachOther_invalid(@TestParameter Mode mode) {
- assertThrows(IllegalArgumentException.class, () -> mode.formatOf("{a}{b}").parse("ab"));
+ public void twoPlaceholdersNextToEachOther_invalid() {
+ assertThrows(IllegalArgumentException.class, () -> new StringFormat("{a}{b}").parse("ab"));
}
@Test
- public void parse_partiallyOverlappingTemplate(@TestParameter Mode mode) {
- assertThat(mode.formatOf("xyz{?}xzz").parse("xyzzxxzz", v -> v)).hasValue("zx");
+ public void parse_partiallyOverlappingTemplate() {
+ assertThat(new StringFormat("xyz{v}xzz").parse("xyzzxxzz", v -> v)).hasValue("zx");
}
@Test
@SuppressWarnings("StringUnformatArgsCheck")
- public void parse_throwsUponIncorrectNumLambdaParameters(@TestParameter Mode mode) {
+ public void parse_throwsUponIncorrectNumLambdaParameters() {
assertThrows(
IllegalArgumentException.class,
- () -> mode.formatOf("1 is {a} or {b}").parse("bad input", Object::toString));
+ () -> new StringFormat("1 is {a} or {b}").parse("bad input", Object::toString));
assertThrows(
IllegalArgumentException.class,
- () -> mode.formatOf("1 is {what}").parse("bad input", String::concat));
+ () -> new StringFormat("1 is {what}").parse("bad input", String::concat));
assertThrows(
IllegalArgumentException.class,
- () -> mode.formatOf("1 is {what}").parse("bad input", (a, b, c) -> a));
+ () -> new StringFormat("1 is {what}").parse("bad input", (a, b, c) -> a));
assertThrows(
IllegalArgumentException.class,
- () -> mode.formatOf("1 is {what}").parse("bad input", (a, b, c, d) -> a));
+ () -> new StringFormat("1 is {what}").parse("bad input", (a, b, c, d) -> a));
assertThrows(
IllegalArgumentException.class,
- () -> mode.formatOf("1 is {what}").parse("bad input", (a, b, c, d, e) -> a));
+ () -> new StringFormat("1 is {what}").parse("bad input", (a, b, c, d, e) -> a));
assertThrows(
IllegalArgumentException.class,
- () -> mode.formatOf("1 is {what}").parse("bad input", (a, b, c, d, e, f) -> a));
+ () -> new StringFormat("1 is {what}").parse("bad input", (a, b, c, d, e, f) -> a));
}
@Test
@@ -539,66 +524,38 @@ public void scan_emptyTemplate_nonEmptyInput() {
ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ImmutableList.of());
}
- @Test
- public void scan_strict_emptyTemplate_nonEmptyInput() {
- assertThat(Mode.NO_EMPTY_MATCH.formatOf("").scan(".")).isEmpty();
- assertThat(Mode.NO_EMPTY_MATCH.formatOf("").scan("foo")).isEmpty();
- }
-
- @Test
- public void scan_strict_withAllValidChars() {
- StringFormat format = StringFormat.strict("{user: {user_id}}", DIGIT);
- assertThat(format.scan("{user: 123}", id -> Integer.parseInt(id))).containsExactly(123);
- assertThat(format.scan("{user: 123}, {user: 456}", id -> Integer.parseInt(id)))
- .containsExactly(123, 456)
- .inOrder();
- }
-
- @Test
- public void scan_strict_invalidCharsFiltered() {
- StringFormat format = StringFormat.strict("{user: {user_id}}", DIGIT);
- assertThat(format.scan("{user: 12x}", id -> Integer.parseInt(id))).isEmpty();
- assertThat(format.scan("{user: 12x}, {user: 456}", id -> Integer.parseInt(id)))
- .containsExactly(456);
- }
-
@Test
public void scan_emptyTemplate_emptyInput() {
assertThat(new StringFormat("").scan("")).containsExactly(ImmutableList.of());
}
@Test
- public void scan_strict_emptyTemplate_emptyInput() {
- assertThat(Mode.NO_EMPTY_MATCH.formatOf("").scan("")).isEmpty();
- }
-
- @Test
- public void scan_singlePlaceholder(@TestParameter Mode mode) {
- assertThat(mode.formatOf("[id={id}]").scan("id=1", id -> id)).isEmpty();
- assertThat(mode.formatOf("[id={id}]").scan("[id=foo]", id -> id)).containsExactly("foo");
- assertThat(mode.formatOf("[id={id}]").scan("[id=foo][id=bar]", id -> id))
+ public void scan_singlePlaceholder() {
+ assertThat(new StringFormat("[id={id}]").scan("id=1", id -> id)).isEmpty();
+ assertThat(new StringFormat("[id={id}]").scan("[id=foo]", id -> id)).containsExactly("foo");
+ assertThat(new StringFormat("[id={id}]").scan("[id=foo][id=bar]", id -> id))
.containsExactly("foo", "bar")
.inOrder();
}
@Test
- public void scan_singlePlaceholder_withEllipsis(@TestParameter Mode mode) {
- assertThat(mode.formatOf("[id={...}]").scan("id=1")).isEmpty();
- assertThat(mode.formatOf("[id={...}]").scan("[id=foo]")).containsExactly(ImmutableList.of());
- assertThat(mode.formatOf("[id={...}]").scan("[id=foo][id=bar]"))
+ public void scan_singlePlaceholder_withEllipsis() {
+ assertThat(new StringFormat("[id={...}]").scan("id=1")).isEmpty();
+ assertThat(new StringFormat("[id={...}]").scan("[id=foo]")).containsExactly(ImmutableList.of());
+ assertThat(new StringFormat("[id={...}]").scan("[id=foo][id=bar]"))
.containsExactly(ImmutableList.of(), ImmutableList.of())
.inOrder();
}
@Test
- public void scan_singlePlaceholder_emptyInput(@TestParameter Mode mode) {
- assertThat(mode.formatOf("[id={id}]").scan("", id -> id)).isEmpty();
+ public void scan_singlePlaceholder_emptyInput() {
+ assertThat(new StringFormat("[id={id}]").scan("", id -> id)).isEmpty();
}
@Test
- public void scan_singlePlaceholder_nullFilteredOut(@TestParameter Mode mode) {
- assertThat(mode.formatOf("[id={id}]").scan("[id=foo]", id -> null)).isEmpty();
- assertThat(mode.formatOf("[id={id}]").scan("[id=foo][id=]", id -> id.isEmpty() ? null : id))
+ public void scan_singlePlaceholder_nullFilteredOut() {
+ assertThat(new StringFormat("[id={id}]").scan("[id=foo]", id -> null)).isEmpty();
+ assertThat(new StringFormat("[id={id}]").scan("[id=foo][id=]", id -> id.isEmpty() ? null : id))
.containsExactly("foo");
}
@@ -610,35 +567,30 @@ public void scan_emptyPlaceholderValue() {
}
@Test
- public void scan_strict_emptyPlaceholderValue() {
- assertThat(Mode.NO_EMPTY_MATCH.formatOf("/{a}/{b}/").scan("/foo/bar//zoo//", (a, b) -> a + b))
- .containsExactly("foobar");
- }
-
- @Test
- public void scan_twoPlaceholders(@TestParameter Mode mode) {
- assertThat(mode.formatOf("[id={id}, name={name}]").scan("id=1", (id, name) -> id + "," + name))
+ public void scan_twoPlaceholders() {
+ assertThat(
+ new StringFormat("[id={id}, name={name}]").scan("id=1", (id, name) -> id + "," + name))
.isEmpty();
assertThat(
- mode.formatOf("[id={id}, name={name}]")
+ new StringFormat("[id={id}, name={name}]")
.scan("[id=foo, name=bar]", (id, name) -> id + "," + name))
.containsExactly("foo,bar");
assertThat(
- mode.formatOf("[id={id}, name={name}]")
+ new StringFormat("[id={id}, name={name}]")
.scan("[id=foo, name=bar][id=zoo, name=boo]", (id, name) -> id + "," + name))
.containsExactly("foo,bar", "zoo,boo")
.inOrder();
}
@Test
- public void scan_twoPlaceholders_withEllipsis(@TestParameter Mode mode) {
+ public void scan_twoPlaceholders_withEllipsis() {
assertThat(
- mode.formatOf("[id={...}, name={name}]")
+ new StringFormat("[id={...}, name={name}]")
.scan("[id=foo, name=bar]")
.map(l -> l.stream().map(Substring.Match::toString).collect(toImmutableList())))
.containsExactly(ImmutableList.of("bar"));
assertThat(
- mode.formatOf("[id={...}, name={name}]")
+ new StringFormat("[id={...}, name={name}]")
.scan("[id=, name=bar][id=zoo, name=boo]")
.map(l -> l.stream().map(Substring.Match::toString).collect(toImmutableList())))
.containsExactly(ImmutableList.of("bar"), ImmutableList.of("boo"))
@@ -646,23 +598,24 @@ public void scan_twoPlaceholders_withEllipsis(@TestParameter Mode mode) {
}
@Test
- public void scan_twoPlaceholders_withEllipsis_usingLambda(@TestParameter Mode mode) {
- assertThat(mode.formatOf("[id={id}, name={...}]").scan("[id=foo, name=bar]", id -> id))
+ public void scan_twoPlaceholders_withEllipsis_usingLambda() {
+ assertThat(new StringFormat("[id={id}, name={...}]").scan("[id=foo, name=bar]", id -> id))
.containsExactly("foo");
assertThat(
- mode.formatOf("[id={...}, name={name}]")
+ new StringFormat("[id={...}, name={name}]")
.scan("[id=, name=bar][id=zoo, name=boo]", name -> name))
.containsExactly("bar", "boo")
.inOrder();
}
@Test
- public void scan_twoPlaceholders_nullFilteredOut(@TestParameter Mode mode) {
+ public void scan_twoPlaceholders_nullFilteredOut() {
assertThat(
- mode.formatOf("[id={id}, name={name}]").scan("[id=foo, name=bar]", (id, name) -> null))
+ new StringFormat("[id={id}, name={name}]")
+ .scan("[id=foo, name=bar]", (id, name) -> null))
.isEmpty();
assertThat(
- mode.formatOf("[id={id}, name={name}]")
+ new StringFormat("[id={id}, name={name}]")
.scan(
"[id=, name=bar][id=zoo, name=boo]",
(id, name) -> id.isEmpty() ? null : id + "," + name))
@@ -670,66 +623,68 @@ public void scan_twoPlaceholders_nullFilteredOut(@TestParameter Mode mode) {
}
@Test
- public void scan_twoPlaceholders_emptyInput(@TestParameter Mode mode) {
- assertThat(mode.formatOf("[id={id}, name={name}]").scan("", (id, name) -> id + "," + name))
+ public void scan_twoPlaceholders_emptyInput() {
+ assertThat(new StringFormat("[id={id}, name={name}]").scan("", (id, name) -> id + "," + name))
.isEmpty();
}
@Test
- public void scan_threePlaceholders(@TestParameter Mode mode) {
- assertThat(mode.formatOf("[a={a}, b={b}, c={c}]").scan("a=1,b=2,c", (a, b, c) -> a + b + c))
+ public void scan_threePlaceholders() {
+ assertThat(new StringFormat("[a={a}, b={b}, c={c}]").scan("a=1,b=2,c", (a, b, c) -> a + b + c))
.isEmpty();
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}]").scan("[a=1, b=2, c=3]", (a, b, c) -> a + b + c))
+ new StringFormat("[a={a}, b={b}, c={c}]")
+ .scan("[a=1, b=2, c=3]", (a, b, c) -> a + b + c))
.containsExactly("123");
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}]")
+ new StringFormat("[a={a}, b={b}, c={c}]")
.scan("[a=1, b=2, c=3] [a=x, b=y, c=z]", (a, b, c) -> a + b + c))
.containsExactly("123", "xyz")
.inOrder();
}
@Test
- public void scan_threePlaceholders_nullFilteredOut(@TestParameter Mode mode) {
- assertThat(mode.formatOf("[a={a}, b={b}, c={c}]").scan("[a=1, b=2, c=3]", (a, b, c) -> null))
+ public void scan_threePlaceholders_nullFilteredOut() {
+ assertThat(new StringFormat("[a={a}, b={b}, c={c}]").scan("[a=1, b=2, c=3]", (a, b, c) -> null))
.isEmpty();
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}]")
+ new StringFormat("[a={a}, b={b}, c={c}]")
.scan(
"[a=1, b=2, c=3] [a=x, b=, c=z]", (a, b, c) -> b.isEmpty() ? null : a + b + c))
.containsExactly("123");
}
@Test
- public void scan_threePlaceholders_emptyInput(@TestParameter Mode mode) {
- assertThat(mode.formatOf("[a={a}, b={b}, c={c}]").scan("", (a, b, c) -> a + b + c)).isEmpty();
+ public void scan_threePlaceholders_emptyInput() {
+ assertThat(new StringFormat("[a={a}, b={b}, c={c}]").scan("", (a, b, c) -> a + b + c))
+ .isEmpty();
}
@Test
- public void scan_fourPlaceholders(@TestParameter Mode mode) {
+ public void scan_fourPlaceholders() {
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}]")
.scan("a=1,b=2,c=3,d", (a, b, c, d) -> a + b + c + d))
.isEmpty();
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}]")
.scan("[a=1, b=2, c=3, d=4]", (a, b, c, d) -> a + b + c + d))
.containsExactly("1234");
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}]")
.scan("[a=1, b=2, c=3, d=4] [a=z, b=y, c=x, d=w]", (a, b, c, d) -> a + b + c + d))
.containsExactly("1234", "zyxw")
.inOrder();
}
@Test
- public void scan_fourPlaceholders_nullFilteredOut(@TestParameter Mode mode) {
+ public void scan_fourPlaceholders_nullFilteredOut() {
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}]")
.scan("[a=1, b=2, c=3, d=4]", (a, b, c, d) -> null))
.isEmpty();
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}]")
.scan(
"[a=1, b=2, c=3, d=4] [a=z, b=y, c=x, d=]",
(a, b, c, d) -> d.isEmpty() ? null : a + b + c + d))
@@ -738,24 +693,25 @@ public void scan_fourPlaceholders_nullFilteredOut(@TestParameter Mode mode) {
}
@Test
- public void scan_fourPlaceholders_emptyInput(@TestParameter Mode mode) {
+ public void scan_fourPlaceholders_emptyInput() {
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}]").scan("", (a, b, c, d) -> a + b + c + d))
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}]")
+ .scan("", (a, b, c, d) -> a + b + c + d))
.isEmpty();
}
@Test
- public void scan_fivePlaceholders(@TestParameter Mode mode) {
+ public void scan_fivePlaceholders() {
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}, e={e}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}, e={e}]")
.scan("a=1,b=2,c=3,d", (a, b, c, d, e) -> a + b + c + d + e))
.isEmpty();
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}, e={e}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}, e={e}]")
.scan("[a=1, b=2, c=3, d=4, e=5]", (a, b, c, d, e) -> a + b + c + d + e))
.containsExactly("12345");
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}, e={e}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}, e={e}]")
.scan(
"[a=1, b=2, c=3, d=4, e=5] [a=z, b=y, c=x, d=w, e=v]",
(a, b, c, d, e) -> a + b + c + d + e))
@@ -764,13 +720,13 @@ public void scan_fivePlaceholders(@TestParameter Mode mode) {
}
@Test
- public void scan_fivePlaceholders_nullFilteredOut(@TestParameter Mode mode) {
+ public void scan_fivePlaceholders_nullFilteredOut() {
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}, e={e}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}, e={e}]")
.scan("[a=1, b=2, c=3, d=4, e=5]", (a, b, c, d, e) -> null))
.isEmpty();
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}, e={e}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}, e={e}]")
.scan(
"[a=, b=2, c=3, d=4, e=5] [a=z, b=y, c=x, d=w, e=v]",
(a, b, c, d, e) -> a.isEmpty() ? null : a + b + c + d + e))
@@ -778,26 +734,26 @@ public void scan_fivePlaceholders_nullFilteredOut(@TestParameter Mode mode) {
}
@Test
- public void scan_fivePlaceholders_emptyInput(@TestParameter Mode mode) {
+ public void scan_fivePlaceholders_emptyInput() {
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}, e={e}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}, e={e}]")
.scan("", (a, b, c, d, e) -> a + b + c + d + e))
.isEmpty();
}
@Test
- public void scan_sixPlaceholders(@TestParameter Mode mode) {
+ public void scan_sixPlaceholders() {
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}, e={e}, f={f}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}, e={e}, f={f}]")
.scan("a=1, b=2, c=3, d=4, e=5, f", (a, b, c, d, e, f) -> a + b + c + d + e + f))
.isEmpty();
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}, e={e}, f={f}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}, e={e}, f={f}]")
.scan(
"[a=1, b=2, c=3, d=4, e=5, f=6]", (a, b, c, d, e, f) -> a + b + c + d + e + f))
.containsExactly("123456");
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}, e={e}, f={f}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}, e={e}, f={f}]")
.scan(
"[a=1, b=2, c=3, d=4, e=5, f=6] [a=z, b=y, c=x, d=w, e=v, f=u]",
(a, b, c, d, e, f) -> a + b + c + d + e + f))
@@ -806,13 +762,13 @@ public void scan_sixPlaceholders(@TestParameter Mode mode) {
}
@Test
- public void scan_sixPlaceholders_nullFiltered(@TestParameter Mode mode) {
+ public void scan_sixPlaceholders_nullFiltered() {
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}, e={e}, f={f}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}, e={e}, f={f}]")
.scan("[a=1, b=2, c=3, d=4, e=5, f=6]", (a, b, c, d, e, f) -> null))
.isEmpty();
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}, e={e}, f={f}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}, e={e}, f={f}]")
.scan(
"[a=1, b=2, c=3, d=, e=5, f=6] [a=z, b=y, c=x, d=w, e=v, f=u]",
(a, b, c, d, e, f) -> d.isEmpty() ? null : a + b + c + d + e + f))
@@ -821,74 +777,74 @@ public void scan_sixPlaceholders_nullFiltered(@TestParameter Mode mode) {
}
@Test
- public void scan_sixPlaceholders_emptyInput(@TestParameter Mode mode) {
+ public void scan_sixPlaceholders_emptyInput() {
assertThat(
- mode.formatOf("[a={a}, b={b}, c={c}, d={d}, e={e}, f={f}]")
+ new StringFormat("[a={a}, b={b}, c={c}, d={d}, e={e}, f={f}]")
.scan("", (a, b, c, d, e, f) -> a + b + c + d + e + f))
.isEmpty();
}
@Test
- public void scan_suffixConsumed(@TestParameter Mode mode) {
- assertThat(mode.formatOf("/{a}/{b}/").scan("/foo/bar//zoo/boo/", (a, b) -> a + b))
+ public void scan_suffixConsumed() {
+ assertThat(new StringFormat("/{a}/{b}/").scan("/foo/bar//zoo/boo/", (a, b) -> a + b))
.containsExactly("foobar", "zooboo")
.inOrder();
}
@Test
- public void scan_skipsNonMatchingCharsFromBeginning(@TestParameter Mode mode) {
- assertThat(mode.formatOf("[id={id}]").scan("whatever [id=foo] [id=bar]", id -> id))
+ public void scan_skipsNonMatchingCharsFromBeginning() {
+ assertThat(new StringFormat("[id={id}]").scan("whatever [id=foo] [id=bar]", id -> id))
.containsExactly("foo", "bar")
.inOrder();
assertThat(
- mode.formatOf("[k={key}, v={value}]")
+ new StringFormat("[k={key}, v={value}]")
.scan("whatever [k=one, v=1] [k=two, v=2]", (k, v) -> k + ":" + v))
.containsExactly("one:1", "two:2")
.inOrder();
}
@Test
- public void scan_skipsNonMatchingCharsFromMiddle(@TestParameter Mode mode) {
- assertThat(mode.formatOf("[id={id}]").scan("[id=foo] [id=bar]", id -> id))
+ public void scan_skipsNonMatchingCharsFromMiddle() {
+ assertThat(new StringFormat("[id={id}]").scan("[id=foo] [id=bar]", id -> id))
.containsExactly("foo", "bar")
.inOrder();
assertThat(
- mode.formatOf("[k={key}, v={value}]")
+ new StringFormat("[k={key}, v={value}]")
.scan("[k=one, v=1] and then [k=two, v=2]", (k, v) -> k + ":" + v))
.containsExactly("one:1", "two:2")
.inOrder();
}
@Test
- public void scan_skipsNonMatchingCharsFromEnd(@TestParameter Mode mode) {
- assertThat(mode.formatOf("[id={id}]").scan("[id=foo] [id=bar];[id=baz", id -> id))
+ public void scan_skipsNonMatchingCharsFromEnd() {
+ assertThat(new StringFormat("[id={id}]").scan("[id=foo] [id=bar];[id=baz", id -> id))
.containsExactly("foo", "bar")
.inOrder();
assertThat(
- mode.formatOf("[k={key}, v={value}]")
+ new StringFormat("[k={key}, v={value}]")
.scan("[k=one, v=1][k=two, v=2];[k=three,v]", (k, v) -> k + ":" + v))
.containsExactly("one:1", "two:2")
.inOrder();
}
@Test
- public void scan_skipsPartialMatches(@TestParameter Mode mode) {
- assertThat(mode.formatOf("[id={id}]").scan("[id [id=bar];[id=baz", id -> id))
+ public void scan_skipsPartialMatches() {
+ assertThat(new StringFormat("[id={id}]").scan("[id [id=bar];[id=baz", id -> id))
.containsExactly("bar")
.inOrder();
- assertThat(mode.formatOf("[[id={id}]]").scan("[[id [[[id=bar]];[id=baz", id -> id))
+ assertThat(new StringFormat("[[id={id}]]").scan("[[id [[[id=bar]];[id=baz", id -> id))
.containsExactly("bar")
.inOrder();
}
@Test
- public void scan_singlePlaceholderOnly(@TestParameter Mode mode) {
- assertThat(mode.formatOf("{s}").scan("whatever", s -> s)).containsExactly("whatever");
+ public void scan_singlePlaceholderOnly() {
+ assertThat(new StringFormat("{s}").scan("whatever", s -> s)).containsExactly("whatever");
}
@Test
- public void scan_singleEllipsisOnly(@TestParameter Mode mode) {
- assertThat(mode.formatOf("{...}").scan("whatever")).containsExactly(ImmutableList.of());
+ public void scan_singleEllipsisOnly() {
+ assertThat(new StringFormat("{...}").scan("whatever")).containsExactly(ImmutableList.of());
assertThat(new StringFormat("{...}").scan("")).containsExactly(ImmutableList.of());
}
@@ -898,84 +854,83 @@ public void scan_singlePlaceholderOnly_emptyInput() {
}
@Test
- public void scan_strict_singlePlaceholderOnly_emptyInput() {
- assertThat(Mode.NO_EMPTY_MATCH.formatOf("{s}").scan("", s -> s)).isEmpty();
- }
-
- @Test
- public void scan_placeholderAtBeginning(@TestParameter Mode mode) {
- assertThat(mode.formatOf("{s} ").scan("a ", s -> s)).containsExactly("a");
- assertThat(mode.formatOf("{s} ").scan("abc d ", s -> s)).containsExactly("abc", "d").inOrder();
+ public void scan_placeholderAtBeginning() {
+ assertThat(new StringFormat("{s} ").scan("a ", s -> s)).containsExactly("a");
+ assertThat(new StringFormat("{s} ").scan("abc d ", s -> s))
+ .containsExactly("abc", "d")
+ .inOrder();
}
@Test
- public void scan_placeholderAtEnd(@TestParameter Mode mode) {
- assertThat(mode.formatOf(" {s}").scan(" a", s -> s)).containsExactly("a");
- assertThat(mode.formatOf(" {s}").scan(" abc d ", s -> s)).containsExactly("abc d ").inOrder();
- assertThat(mode.formatOf(" {a} {b}").scan(" abc d ", (a, b) -> a + "," + b))
+ public void scan_placeholderAtEnd() {
+ assertThat(new StringFormat(" {s}").scan(" a", s -> s)).containsExactly("a");
+ assertThat(new StringFormat(" {s}").scan(" abc d ", s -> s))
+ .containsExactly("abc d ")
+ .inOrder();
+ assertThat(new StringFormat(" {a} {b}").scan(" abc d ", (a, b) -> a + "," + b))
.containsExactly("abc,d ")
.inOrder();
}
@Test
@SuppressWarnings("StringUnformatArgsCheck")
- public void scan_throwsUponIncorrectNumLambdaParameters(@TestParameter Mode mode) {
+ public void scan_throwsUponIncorrectNumLambdaParameters() {
assertThrows(
IllegalArgumentException.class,
- () -> mode.formatOf("1 is {a} or {b}").scan("bad input", Object::toString));
+ () -> new StringFormat("1 is {a} or {b}").scan("bad input", Object::toString));
assertThrows(
IllegalArgumentException.class,
- () -> mode.formatOf("1 is {what}").scan("bad input", String::concat));
+ () -> new StringFormat("1 is {what}").scan("bad input", String::concat));
assertThrows(
IllegalArgumentException.class,
- () -> mode.formatOf("1 is {what}").scan("bad input", (a, b, c) -> a));
+ () -> new StringFormat("1 is {what}").scan("bad input", (a, b, c) -> a));
assertThrows(
IllegalArgumentException.class,
- () -> mode.formatOf("1 is {what}").scan("bad input", (a, b, c, d) -> a));
+ () -> new StringFormat("1 is {what}").scan("bad input", (a, b, c, d) -> a));
assertThrows(
IllegalArgumentException.class,
- () -> mode.formatOf("1 is {what}").scan("bad input", (a, b, c, d, e) -> a));
+ () -> new StringFormat("1 is {what}").scan("bad input", (a, b, c, d, e) -> a));
assertThrows(
IllegalArgumentException.class,
- () -> mode.formatOf("1 is {what}").scan("bad input", (a, b, c, d, e, f) -> a));
+ () -> new StringFormat("1 is {what}").scan("bad input", (a, b, c, d, e, f) -> a));
}
@Test
- public void format_placeholdersFilled(@TestParameter Mode mode) {
- assertThat(mode.formatOf("{a} + {b} = {c}").format(1, 2, 3)).isEqualTo("1 + 2 = 3");
+ public void format_placeholdersFilled() {
+ assertThat(new StringFormat("{a} + {b} = {c}").format(1, 2, 3)).isEqualTo("1 + 2 = 3");
}
@Test
- public void format_ellipsisFilled(@TestParameter Mode mode) {
- assertThat(mode.formatOf("{a} + {b} = {...}").format(1, 2, 3)).isEqualTo("1 + 2 = 3");
+ public void format_ellipsisFilled() {
+ assertThat(new StringFormat("{a} + {b} = {...}").format(1, 2, 3)).isEqualTo("1 + 2 = 3");
}
@Test
- public void format_nullValueAllowed(@TestParameter Mode mode) {
- assertThat(mode.formatOf("{key} == {value}").format("x", null)).isEqualTo("x == null");
+ public void format_nullValueAllowed() {
+ assertThat(new StringFormat("{key} == {value}").format("x", null)).isEqualTo("x == null");
}
@Test
- public void format_noPlaceholder(@TestParameter Mode mode) {
- assertThat(mode.formatOf("hello").format()).isEqualTo("hello");
+ public void format_noPlaceholder() {
+ assertThat(new StringFormat("hello").format()).isEqualTo("hello");
}
@Test
- public void format_withEmptyValue(@TestParameter Mode mode) {
- assertThat(mode.formatOf("{a} + {b} = {c}").format(1, 2, "")).isEqualTo("1 + 2 = ");
+ public void format_withEmptyValue() {
+ assertThat(new StringFormat("{a} + {b} = {c}").format(1, 2, "")).isEqualTo("1 + 2 = ");
}
@Test
@SuppressWarnings("StringFormatArgsCheck")
- public void format_tooFewArgs(@TestParameter Mode mode) {
- assertThrows(IllegalArgumentException.class, () -> mode.formatOf("{foo}:{bar}").format(1));
+ public void format_tooFewArgs() {
+ assertThrows(IllegalArgumentException.class, () -> new StringFormat("{foo}:{bar}").format(1));
}
@Test
@SuppressWarnings("StringFormatArgsCheck")
- public void format_tooManyArgs(@TestParameter Mode mode) {
+ public void format_tooManyArgs() {
assertThrows(
- IllegalArgumentException.class, () -> mode.formatOf("{foo}:{bar}").format(1, 2, 3));
+ IllegalArgumentException.class, () -> new StringFormat("{foo}:{bar}").format(1, 2, 3));
}
@Test
@@ -1165,8 +1120,8 @@ public void reverseList_multipleElementsReversed() {
}
@Test
- public void testToString(@TestParameter Mode mode) {
- assertThat(mode.formatOf("projects/{project}/locations/{location}").toString())
+ public void testToString() {
+ assertThat(new StringFormat("projects/{project}/locations/{location}").toString())
.isEqualTo("projects/{project}/locations/{location}");
}
@@ -1182,23 +1137,6 @@ private static OptionalSubject assertPatternMatch(Substring.Pattern pattern, Str
.that(pattern.in(input).map(m -> m.before() + "[" + m + "]" + m.after()));
}
- private enum Mode {
- ANY_MATCH {
- @Override
- StringFormat formatOf(String format) {
- return new StringFormat(format);
- }
- },
- NO_EMPTY_MATCH {
- @Override
- StringFormat formatOf(String format) {
- return StringFormat.strict(format, c -> true);
- }
- };
-
- abstract StringFormat formatOf(@CompileTimeConstant String format);
- }
-
/** How we expect SPI providers to use {@link StringFormat#template}. */
private static final class BigQuery {
private final String query;
diff --git a/mug/src/test/java/com/google/mu/util/concurrent/RetryerFunctionalTest.java b/mug/src/test/java/com/google/mu/util/concurrent/RetryerFunctionalTest.java
index b65c0827a5..34522eae9f 100644
--- a/mug/src/test/java/com/google/mu/util/concurrent/RetryerFunctionalTest.java
+++ b/mug/src/test/java/com/google/mu/util/concurrent/RetryerFunctionalTest.java
@@ -20,7 +20,7 @@
import static com.google.mu.util.concurrent.FutureAssertions.assertPending;
import static java.util.Arrays.asList;
import static org.junit.jupiter.api.Assertions.assertThrows;
-import static org.mockito.Matchers.any;
+import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
@@ -194,7 +194,7 @@ public class RetryerFunctionalTest {
CancellationException cancelled =
assertThrows(CancellationException.class, () -> stage.toCompletableFuture().get());
assertThat(cancelled.getCause()).isInstanceOf(InterruptedException.class);
- assertThat(cancelled.getSuppressed()).asList().containsExactly(exception);
+ // assertThat(cancelled.getSuppressed()).asList().containsExactly(exception);
}
@Test public void interruptedDuringReturnValueRetryRetry()
diff --git a/pom.xml b/pom.xml
index 72e3c8f149..65343fb802 100644
--- a/pom.xml
+++ b/pom.xml
@@ -187,20 +187,6 @@
together with other annotation processors' below. -->
-
-
- org.codehaus.plexus
- plexus-compiler-javac-errorprone
- 2.8
-
-
-
- com.google.errorprone
- error_prone_core
- 2.23.0
-
-
maven-source-plugin