[Test] Allow parse FILE and MODULE directives with other strings between them in old tests
This commit is contained in:
committed by
TeamCityServer
parent
b9e9620ab5
commit
0d058c7c8c
@@ -33,9 +33,8 @@ public class TestFiles {
|
|||||||
*/
|
*/
|
||||||
private static final String MODULE_DELIMITER = ",\\s*";
|
private static final String MODULE_DELIMITER = ",\\s*";
|
||||||
|
|
||||||
private static final Pattern FILE_OR_MODULE_PATTERN = Pattern.compile(
|
private static final Pattern MODULE_PATTERN = Pattern.compile("//\\s*MODULE:\\s*([^()\\n]+)(?:\\(([^()]+(?:" + MODULE_DELIMITER + "[^()]+)*)\\))?\\s*(?:\\(([^()]+(?:" + MODULE_DELIMITER + "[^()]+)*)\\))?\n");
|
||||||
"(?://\\s*MODULE:\\s*([^()\\n]+)(?:\\(([^()]+(?:" + MODULE_DELIMITER + "[^()]+)*)\\))?\\s*(?:\\(([^()]+(?:" + MODULE_DELIMITER + "[^()]+)*)\\))?\\s*)?" +
|
private static final Pattern FILE_PATTERN = Pattern.compile("//\\s*FILE:\\s*(.*)\n");
|
||||||
"//\\s*FILE:\\s*(.*)$", Pattern.MULTILINE);
|
|
||||||
|
|
||||||
private static final Pattern LINE_SEPARATOR_PATTERN = Pattern.compile("\\r\\n|\\r|\\n");
|
private static final Pattern LINE_SEPARATOR_PATTERN = Pattern.compile("\\r\\n|\\r|\\n");
|
||||||
|
|
||||||
@@ -55,10 +54,14 @@ public class TestFiles {
|
|||||||
boolean preserveLocations, boolean parseDirectivesPerFile) {
|
boolean preserveLocations, boolean parseDirectivesPerFile) {
|
||||||
Map<String, M> modules = new HashMap<>();
|
Map<String, M> modules = new HashMap<>();
|
||||||
List<F> testFiles = Lists.newArrayList();
|
List<F> testFiles = Lists.newArrayList();
|
||||||
Matcher matcher = FILE_OR_MODULE_PATTERN.matcher(expectedText);
|
Matcher fileMatcher = FILE_PATTERN.matcher(expectedText);
|
||||||
|
Matcher moduleMatcher = MODULE_PATTERN.matcher(expectedText);
|
||||||
boolean hasModules = false;
|
boolean hasModules = false;
|
||||||
String commonPrefixOrWholeFile;
|
String commonPrefixOrWholeFile;
|
||||||
if (!matcher.find()) {
|
|
||||||
|
boolean fileFound = fileMatcher.find();
|
||||||
|
boolean moduleFound = moduleMatcher.find();
|
||||||
|
if (!fileFound && !moduleFound) {
|
||||||
assert testFileName != null : "testFileName should not be null if no FILE directive defined";
|
assert testFileName != null : "testFileName should not be null if no FILE directive defined";
|
||||||
// One file
|
// One file
|
||||||
testFiles.add(factory.createFile(null, testFileName, expectedText, parseDirectives(expectedText)));
|
testFiles.add(factory.createFile(null, testFileName, expectedText, parseDirectives(expectedText)));
|
||||||
@@ -69,45 +72,64 @@ public class TestFiles {
|
|||||||
int processedChars = 0;
|
int processedChars = 0;
|
||||||
M module = null;
|
M module = null;
|
||||||
boolean firstFileProcessed = false;
|
boolean firstFileProcessed = false;
|
||||||
commonPrefixOrWholeFile = expectedText.substring(0, matcher.start());
|
|
||||||
|
int commonStart;
|
||||||
|
if (moduleFound) {
|
||||||
|
commonStart = moduleMatcher.start();
|
||||||
|
} else {
|
||||||
|
commonStart = fileMatcher.start();
|
||||||
|
}
|
||||||
|
|
||||||
|
commonPrefixOrWholeFile = expectedText.substring(0, commonStart);
|
||||||
|
|
||||||
// Many files
|
// Many files
|
||||||
while (true) {
|
while (true) {
|
||||||
String moduleName = matcher.group(1);
|
if (moduleFound) {
|
||||||
String moduleDependencies = matcher.group(2);
|
String moduleName = moduleMatcher.group(1);
|
||||||
String moduleFriends = matcher.group(3);
|
String moduleDependencies = moduleMatcher.group(2);
|
||||||
if (moduleName != null) {
|
String moduleFriends = moduleMatcher.group(3);
|
||||||
moduleName = moduleName.trim();
|
if (moduleName != null) {
|
||||||
hasModules = true;
|
moduleName = moduleName.trim();
|
||||||
module = factory.createModule(moduleName, parseModuleList(moduleDependencies), parseModuleList(moduleFriends));
|
hasModules = true;
|
||||||
M oldValue = modules.put(moduleName, module);
|
module = factory.createModule(moduleName, parseModuleList(moduleDependencies), parseModuleList(moduleFriends));
|
||||||
assert oldValue == null : "Module with name " + moduleName + " already present in file";
|
M oldValue = modules.put(moduleName, module);
|
||||||
|
assert oldValue == null : "Module with name " + moduleName + " already present in file";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
String fileName = matcher.group(4);
|
boolean nextModuleExists = moduleMatcher.find();
|
||||||
int start = processedChars;
|
moduleFound = nextModuleExists;
|
||||||
|
while (true) {
|
||||||
|
String fileName = fileMatcher.group(1);
|
||||||
|
int start = processedChars;
|
||||||
|
|
||||||
boolean nextFileExists = matcher.find();
|
boolean nextFileExists = fileMatcher.find();
|
||||||
int end;
|
int end;
|
||||||
if (nextFileExists) {
|
if (nextFileExists && nextModuleExists) {
|
||||||
end = matcher.start();
|
end = Math.min(fileMatcher.start(), moduleMatcher.start());
|
||||||
|
}
|
||||||
|
else if (nextFileExists) {
|
||||||
|
end = fileMatcher.start();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
end = expectedText.length();
|
||||||
|
}
|
||||||
|
String fileText = preserveLocations ?
|
||||||
|
substringKeepingLocations(expectedText, start, end) :
|
||||||
|
expectedText.substring(start, end);
|
||||||
|
|
||||||
|
|
||||||
|
String expectedText1 = firstFileProcessed ? commonPrefixOrWholeFile + fileText : fileText;
|
||||||
|
testFiles.add(factory.createFile(module, fileName, fileText,
|
||||||
|
parseDirectivesPerFile ?
|
||||||
|
parseDirectives(expectedText1)
|
||||||
|
: allFilesOrCommonPrefixDirectives));
|
||||||
|
processedChars = end;
|
||||||
|
firstFileProcessed = true;
|
||||||
|
if (!nextFileExists && !nextModuleExists) break;
|
||||||
|
if (nextModuleExists && fileMatcher.start() > moduleMatcher.start()) break;
|
||||||
}
|
}
|
||||||
else {
|
if (!nextModuleExists) break;
|
||||||
end = expectedText.length();
|
|
||||||
}
|
|
||||||
String fileText = preserveLocations ?
|
|
||||||
substringKeepingLocations(expectedText, start, end) :
|
|
||||||
expectedText.substring(start,end);
|
|
||||||
|
|
||||||
|
|
||||||
String expectedText1 = firstFileProcessed ? commonPrefixOrWholeFile + fileText : fileText;
|
|
||||||
testFiles.add(factory.createFile(module, fileName, fileText,
|
|
||||||
parseDirectivesPerFile ?
|
|
||||||
parseDirectives(expectedText1)
|
|
||||||
: allFilesOrCommonPrefixDirectives));
|
|
||||||
processedChars = end;
|
|
||||||
firstFileProcessed = true;
|
|
||||||
if (!nextFileExists) break;
|
|
||||||
}
|
}
|
||||||
assert processedChars == expectedText.length() : "Characters skipped from " +
|
assert processedChars == expectedText.length() : "Characters skipped from " +
|
||||||
processedChars +
|
processedChars +
|
||||||
|
|||||||
Reference in New Issue
Block a user