-
Notifications
You must be signed in to change notification settings - Fork 171
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
additional tests for contains and trigrams (#1078)
Put in some additional test cases for extracting contained strings and trigrams from patterns. Fixes some cases with trigram extraction for repeats that can be absent from the string and still match.
- Loading branch information
1 parent
9e8a488
commit 19e5a8f
Showing
10 changed files
with
156 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...ator-api/src/test/java/com/netflix/spectator/impl/matcher/ContainsPatternMatcherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright 2014-2023 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.netflix.spectator.impl.matcher; | ||
|
||
import com.netflix.spectator.impl.PatternMatcher; | ||
import org.junit.jupiter.api.Assertions; | ||
|
||
public class ContainsPatternMatcherTest extends AbstractPatternMatcherTest { | ||
|
||
@Override | ||
protected void testRE(String regex, String value) { | ||
PatternMatcher matcher = PatternMatcher.compile(regex); | ||
String str = matcher.containedString(); | ||
|
||
// Contains should be more lenient than the actual pattern, so anything that is matched | ||
// by the pattern must be a possible match with the trigrams. | ||
if (str != null && matcher.matches(value)) { | ||
Assertions.assertTrue(value.contains(str)); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
40 changes: 40 additions & 0 deletions
40
...ator-api/src/test/java/com/netflix/spectator/impl/matcher/TrigramsPatternMatcherTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/* | ||
* Copyright 2014-2023 Netflix, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.netflix.spectator.impl.matcher; | ||
|
||
import com.netflix.spectator.impl.PatternMatcher; | ||
import org.junit.jupiter.api.Assertions; | ||
|
||
import java.util.SortedSet; | ||
|
||
public class TrigramsPatternMatcherTest extends AbstractPatternMatcherTest { | ||
|
||
@Override | ||
protected void testRE(String regex, String value) { | ||
PatternMatcher matcher = PatternMatcher.compile(regex); | ||
SortedSet<String> trigrams = matcher.trigrams(); | ||
|
||
// Trigrams should be more lenient than the actual pattern, so anything that is matched | ||
// by the pattern must be a possible match with the trigrams. | ||
if (matcher.matches(value)) { | ||
Assertions.assertTrue(couldMatch(trigrams, value)); | ||
} | ||
} | ||
|
||
private boolean couldMatch(SortedSet<String> trigrams, String value) { | ||
return trigrams.stream().allMatch(value::contains); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters