Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,8 +108,8 @@ public void testSingleRegex() throws Exception {

public void testMultiplePatterns() throws Exception {
final String prefix1 = randomAlphaOfLengthBetween(3, 5);
final String prefix2 = randomAlphaOfLengthBetween(5, 8);
final String prefix3 = randomAlphaOfLengthBetween(10, 12);
final String prefix2 = randomValueOtherThanMany(s -> s.startsWith(prefix1), () -> randomAlphaOfLengthBetween(5, 8));
final String prefix3 = randomValueOtherThanMany(s -> s.startsWith(prefix1), () -> randomAlphaOfLengthBetween(10, 12));
final String suffix1 = randomAlphaOfLengthBetween(5, 10);
final String suffix2 = randomAlphaOfLengthBetween(8, 12);
final String exact1 = randomValueOtherThanMany(
Expand All @@ -129,19 +129,32 @@ public void testMultiplePatterns() throws Exception {
List.of(prefix1 + "*", prefix2 + "?", "/" + prefix3 + "@/", "*" + suffix1, "/@" + suffix2 + "/", exact1, exact2, exact3)
);

final List<Character> nonAlpha = "@/#$0123456789()[]{}<>;:%&".chars()
.mapToObj(c -> Character.valueOf((char) c))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional nit: I think boxing happens automatically here, i.e., c -> (char) c) is sufficient.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would, though I think explicit is preferable in this case.
I guess it's just going to come down to personal preference, but I like the clarity of the explicit boxing.

.collect(Collectors.toList());

assertMatch(matcher, exact1);
assertMatch(matcher, exact2);
assertMatch(matcher, exact3);
assertMatch(matcher, randomAlphaOfLength(3) + suffix1);
assertMatch(matcher, randomAlphaOfLength(3) + suffix2);

// Prefix 1 uses '*', it should match any number of trailing chars.
assertMatch(matcher, prefix1 + randomAlphaOfLengthBetween(1, 5));
assertMatch(matcher, prefix2 + randomAlphaOfLength(1));
assertMatch(matcher, prefix3 + randomAlphaOfLengthBetween(1, 5));
assertMatch(matcher, prefix1 + randomFrom(nonAlpha));
assertMatch(matcher, prefix1 + randomFrom(nonAlpha) + randomFrom(nonAlpha));

final char[] nonAlpha = "@/#$0123456789()[]{}<>;:%&".toCharArray();
// Prefix 2 uses a `?`, it should match any single trailing char, but not 2 chars.
// (We don't test with a trailing alpha because it might match one of the matched suffixes)
assertMatch(matcher, prefix2 + randomAlphaOfLength(1));
assertMatch(matcher, prefix2 + randomFrom(nonAlpha));
assertNoMatch(matcher, prefix2 + randomFrom(nonAlpha) + randomFrom(nonAlpha));
assertNoMatch(matcher, prefix2 + randomAlphaOfLength(1) + randomFrom(nonAlpha));

// Prefix 2 uses a `?`
assertNoMatch(matcher, prefix2 + randomFrom(nonAlpha));
// Prefix 3 uses a regex with '@', it should match any number of trailing chars.
assertMatch(matcher, prefix3 + randomAlphaOfLengthBetween(1, 5));
assertMatch(matcher, prefix3 + randomFrom(nonAlpha));
assertMatch(matcher, prefix3 + randomFrom(nonAlpha) + randomFrom(nonAlpha));

for (String pattern : List.of(exact1, exact2, exact3, suffix1, suffix2, exact1, exact2, exact3)) {
assertNoMatch(matcher, randomFrom(nonAlpha) + pattern + randomFrom(nonAlpha));
Expand Down