提交 0a241e3a 编写于 作者: S Skylot

core tests: add custom string matchers

上级 37857e88
package jadx.tests.utils;
import org.hamcrest.core.SubstringMatcher;
public class CountString extends SubstringMatcher {
private final int count;
public CountString(int count, String substring) {
super(substring);
this.count = count;
}
@Override
protected boolean evalSubstringOf(String string) {
return this.count == countStr(string, substring);
}
@Override
protected String relationship() {
return "containing " + count + " occurrence of";
}
private static int countStr(String string, String substring) {
int cnt = 0;
int idx = 0;
while ((idx = string.indexOf(substring, idx)) != -1) {
idx++;
cnt++;
}
return cnt;
}
}
package jadx.tests.utils;
import org.hamcrest.Matcher;
public class JadxMatchers {
public static Matcher<String> countString(int count, String substring) {
return new CountString(count, substring);
}
public static Matcher<String> containsOne(String substring) {
return new CountString(1, substring);
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册