for (String testsDirectory : TESTS.get(phpVersion)) {
for (final String fileName : getPDTTFiles(testsDirectory,
Activator.getDefault().getBundle())) {
try {
final PdttFile pdttFile = new PdttFile(Activator
.getDefault().getBundle(), fileName);
filesMap.put(pdttFile, null);
phpVerSuite.addTest(new FormatterLinuxAutoEditTests("Linux" + " - /"
+ phpVersion
.getAlias() + " - /"
+ fileName) {
protected void setUp() throws Exception {
PHPCoreTests.setProjectPhpVersion(project,
phpVersion);
}
protected void runTest() throws Throwable {
IFile file = filesMap.get(pdttFile);
ISourceModule modelElement = (ISourceModule) DLTKCore
.create(file);
if (ScriptModelUtil.isPrimary(modelElement))
modelElement.becomeWorkingCopy(
new IProblemRequestor() {
public void acceptProblem(
IProblem problem) {
// TODO Auto-generated
// method stub
}
public void beginReporting() {
// TODO Auto-generated
// method stub
}
public void endReporting() {
// TODO Auto-generated
// method stub
}
public boolean isActive() {
// TODO Auto-generated
// method stub
return false;
}
}, null);
IStructuredModel modelForEdit = StructuredModelManager
.getModelManager()
.getModelForEdit(file);
try {
IDocument document = modelForEdit
.getStructuredDocument();
String beforeFormat = document.get();
String data = document.get();
int offset = data.lastIndexOf(OFFSET_CHAR);
if (offset == -1) {
throw new IllegalArgumentException(
data+",offset character is not set");
}
// replace the offset character
data = data.substring(0, offset)
+ data.substring(offset + 1);
document.set(data);
MainAutoEditStrategy indentLineAutoEditStrategy = new MainAutoEditStrategy();
DocumentCommand cmd = new DocumentCommand() {
};
cmd.offset = offset;
cmd.length = 0;
if (pdttFile.getOther() != null) {
cmd.text = pdttFile.getOther().replaceAll("\r\n", "\n");
} else {
cmd.text = "\n";
}
cmd.doit = true;
cmd.shiftsCaret = true;
cmd.caretOffset = -1;
indentLineAutoEditStrategy
.customizeDocumentCommand(document,
cmd);
document.replace(cmd.offset, cmd.length,
cmd.text);
assertContents(pdttFile.getExpected().replaceAll("\r\n", "\n"),
document.get());
// change the document text as was before
// the formatting
document.set(beforeFormat);