Extracting test name from regex matcher.
This commit is contained in:
@@ -23,6 +23,7 @@ import org.jetbrains.jet.JetTestUtils;
|
|||||||
import org.jetbrains.jet.utils.Printer;
|
import org.jetbrains.jet.utils.Printer;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
public class SimpleTestMethodModel implements TestMethodModel {
|
public class SimpleTestMethodModel implements TestMethodModel {
|
||||||
@@ -50,14 +51,19 @@ public class SimpleTestMethodModel implements TestMethodModel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
String fileName = FileUtil.getNameWithoutExtension(file.getName());
|
Matcher matcher = filenamePattern.matcher(file.getName());
|
||||||
|
boolean found = matcher.find();
|
||||||
|
assert found : file.getName() + " isn't matched by regex " + filenamePattern.pattern();
|
||||||
|
assert matcher.groupCount() == 2 : filenamePattern.pattern();
|
||||||
|
String extractedName = matcher.group(1);
|
||||||
|
|
||||||
String unescapedName;
|
String unescapedName;
|
||||||
if (rootDir.equals(file.getParentFile())) {
|
if (rootDir.equals(file.getParentFile())) {
|
||||||
unescapedName = fileName;
|
unescapedName = extractedName;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
String relativePath = FileUtil.getRelativePath(rootDir, file.getParentFile());
|
String relativePath = FileUtil.getRelativePath(rootDir, file.getParentFile());
|
||||||
unescapedName = relativePath + "-" + StringUtil.capitalize(fileName);
|
unescapedName = relativePath + "-" + StringUtil.capitalize(extractedName);
|
||||||
}
|
}
|
||||||
return "test" + StringUtil.capitalize(TestGeneratorUtil.escapeForJavaIdentifier(unescapedName));
|
return "test" + StringUtil.capitalize(TestGeneratorUtil.escapeForJavaIdentifier(unescapedName));
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user