-
Notifications
You must be signed in to change notification settings - Fork 309
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adapt quick assist test suite for new quickAssists extension point
Most of the tests are bad and because they rely on UI behavior they can't even be run by the build server. But the tests exist and I don't want to remove them. If someone has more time available it would be nice if this person could move tests completely away from UI classes.
- Loading branch information
Showing
6 changed files
with
75 additions
and
112 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
103 changes: 0 additions & 103 deletions
103
org.scala-ide.sdt.core.tests/src/org/scalaide/core/quickassist/QuickFixesTests.scala
This file was deleted.
Oops, something went wrong.
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
66 changes: 66 additions & 0 deletions
66
org.scala-ide.sdt.core.tests/src/org/scalaide/core/quickassist/UiQuickAssistTests.scala
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,66 @@ | ||
package org.scalaide.core | ||
package quickassist | ||
|
||
import org.eclipse.jdt.core.compiler.IProblem | ||
import org.eclipse.jdt.ui.JavaUI | ||
import org.eclipse.jface.text.quickassist.IQuickAssistInvocationContext | ||
import org.junit.Assert._ | ||
import org.scalaide.core.internal.jdt.model.ScalaCompilationUnit | ||
import org.scalaide.core.internal.quickassist.QuickAssistProcessor | ||
|
||
import testsetup.TestProjectSetup | ||
|
||
/** | ||
* Provides test behavior that relies on a working UI environment. | ||
*/ | ||
object UiQuickAssistTests extends TestProjectSetup("quickassist") { | ||
|
||
def assertNumberOfProblems(nProblems: Int, problems: Array[IProblem]) { | ||
if (problems.length != nProblems) { | ||
val buf = new StringBuffer("Wrong number of problems, is: ") | ||
buf.append(problems.length).append(", expected: ").append(nProblems).append('\n') | ||
for (problem <- problems) { | ||
buf.append(problem).append(" at ") | ||
buf.append('[').append(problem.getSourceStart()).append(" ,").append(problem.getSourceEnd()).append(']') | ||
buf.append('\n') | ||
} | ||
|
||
assertEquals(buf.toString, nProblems, problems.length) | ||
} | ||
} | ||
|
||
def withQuickFixes(pathToSource: String)(expectedQuickFixes: String*) { | ||
withManyQuickFixesPerLine(pathToSource)(expectedQuickFixes.map(List(_)).toList) | ||
} | ||
|
||
def withManyQuickFixesPerLine(pathToSource: String)(expectedQuickFixesList: List[List[String]]) { | ||
val unit = compilationUnit(pathToSource).asInstanceOf[ScalaCompilationUnit] | ||
|
||
unit.withSourceFile { (src, compiler) => | ||
compiler.askReload(List(unit)).get | ||
|
||
val problems = compiler.problemsOf(unit) | ||
assertTrue("No problems found.", problems.nonEmpty) | ||
assertNumberOfProblems(expectedQuickFixesList.size, problems.toArray) | ||
|
||
val part = JavaUI.openInEditor(unit.getCompilationUnit) | ||
|
||
for ((problem, expectedQuickFixes) <- problems zip expectedQuickFixesList) { | ||
val offset = problem.getSourceStart | ||
val length = problem.getSourceEnd + 1 - offset | ||
val processor = new QuickAssistProcessor(part.getEditorInput, QuickAssistProcessor.DefaultId) | ||
val proposals = processor.computeQuickAssistProposals(new IQuickAssistInvocationContext { | ||
override def getOffset = offset | ||
override def getLength = length | ||
override def getSourceViewer = null | ||
}) | ||
val corrections = proposals.map(_.getDisplayString) | ||
|
||
for (quickFix <- expectedQuickFixes) { | ||
assertTrue("Quick fix " + quickFix + " was not offered. Offered were: " + corrections.mkString(", "), | ||
corrections contains quickFix) | ||
} | ||
} | ||
} | ||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
...ide.sdt.core.tests/src/org/scalaide/core/quickassist/createmethod/CreateMethodTests.scala
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