mirror of https://github.com/apache/kafka.git
MINOR: Update Trogdor StringExpander regex to handle an epilogue (#6123)
Update the Trogdor StringExpander regex to handle an epilogue. Previously the regex would use a lazy quantifier at the end, which meant it would not catch anything after the range expression. Add a unit test. Reviewed-by: Colin P. McCabe <cmccabe@apache.org>
This commit is contained in:
parent
aca52b6d2c
commit
13f679013a
|
@ -29,7 +29,7 @@ import java.util.regex.Pattern;
|
||||||
*/
|
*/
|
||||||
public class StringExpander {
|
public class StringExpander {
|
||||||
private final static Pattern NUMERIC_RANGE_PATTERN =
|
private final static Pattern NUMERIC_RANGE_PATTERN =
|
||||||
Pattern.compile("(.*?)\\[([0-9]*)\\-([0-9]*)\\](.*?)");
|
Pattern.compile("(.*)\\[([0-9]*)\\-([0-9]*)\\](.*)");
|
||||||
|
|
||||||
public static HashSet<String> expand(String val) {
|
public static HashSet<String> expand(String val) {
|
||||||
HashSet<String> set = new HashSet<>();
|
HashSet<String> set = new HashSet<>();
|
||||||
|
|
|
@ -58,5 +58,20 @@ public class StringExpanderTest {
|
||||||
"[[ wow52 ]]"
|
"[[ wow52 ]]"
|
||||||
));
|
));
|
||||||
assertEquals(expected3, StringExpander.expand("[[ wow[50-52] ]]"));
|
assertEquals(expected3, StringExpander.expand("[[ wow[50-52] ]]"));
|
||||||
|
|
||||||
|
HashSet<String> expected4 = new HashSet<>(Arrays.asList(
|
||||||
|
"foo1bar",
|
||||||
|
"foo2bar",
|
||||||
|
"foo3bar"
|
||||||
|
));
|
||||||
|
assertEquals(expected4, StringExpander.expand("foo[1-3]bar"));
|
||||||
|
|
||||||
|
// should expand latest range first
|
||||||
|
HashSet<String> expected5 = new HashSet<>(Arrays.asList(
|
||||||
|
"start[1-3]middle1epilogue",
|
||||||
|
"start[1-3]middle2epilogue",
|
||||||
|
"start[1-3]middle3epilogue"
|
||||||
|
));
|
||||||
|
assertEquals(expected5, StringExpander.expand("start[1-3]middle[1-3]epilogue"));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue