-
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.
Start implementing test suite for save actions
This contains tests for the save action RemoveTrailingWhitespace.
- Loading branch information
Showing
5 changed files
with
90 additions
and
3 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
35 changes: 35 additions & 0 deletions
35
...sdt.core.tests/src/org/scalaide/extensions/saveactions/RemoveTrailingWhitespaceTest.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,35 @@ | ||
package org.scalaide.extensions.saveactions | ||
|
||
import org.junit.Test | ||
|
||
class RemoveTrailingWhitespaceTest extends SaveActionTests { self => | ||
|
||
override def saveAction = new RemoveTrailingWhitespace { | ||
override val document = self.document | ||
} | ||
|
||
@Test | ||
def trailing_whitespace_is_removed() = """|^ | ||
|class X { | ||
| def hello = { $ | ||
| val x = 0 $ | ||
| $ | ||
| val y = 1 $ | ||
| $ | ||
| x + y | ||
| } | ||
|} | ||
| $ | ||
|""".stripMargin becomes """|^ | ||
|class X { | ||
| def hello = { | ||
| val x = 0 | ||
| | ||
| val y = 1 | ||
| | ||
| x + y | ||
| } | ||
|} | ||
| | ||
|""".stripMargin after SaveEvent | ||
} |
10 changes: 10 additions & 0 deletions
10
...cala-ide.sdt.core.tests/src/org/scalaide/extensions/saveactions/SaveActionTestSuite.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,10 @@ | ||
package org.scalaide.extensions.saveactions | ||
|
||
import org.junit.runner.RunWith | ||
import org.junit.runners.Suite | ||
|
||
@RunWith(classOf[Suite]) | ||
@Suite.SuiteClasses(Array( | ||
classOf[RemoveTrailingWhitespaceTest] | ||
)) | ||
class SaveActionTestSuite |
40 changes: 40 additions & 0 deletions
40
org.scala-ide.sdt.core.tests/src/org/scalaide/extensions/saveactions/SaveActionTests.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,40 @@ | ||
package org.scalaide.extensions | ||
package saveactions | ||
|
||
import org.eclipse.jface.text.{Document => EDocument} | ||
import org.scalaide.core.internal.text.TextDocument | ||
import org.scalaide.core.text.Document | ||
import org.scalaide.core.text.TextChange | ||
import org.scalaide.core.ui.TextEditTests | ||
import org.scalaide.extensions.SaveAction | ||
|
||
abstract class SaveActionTests extends TextEditTests { | ||
|
||
def saveAction: SaveAction | ||
|
||
var document: Document = _ | ||
|
||
private var udoc: EDocument = _ | ||
|
||
override def runTest(source: String, operation: Operation) = { | ||
udoc = new EDocument(source) | ||
document = new TextDocument(udoc) | ||
operation.execute() | ||
} | ||
|
||
override def source = udoc.get() | ||
|
||
case object SaveEvent extends Operation { | ||
override def execute() = { | ||
val changes = saveAction.perform() | ||
val sorted = changes.sortBy { | ||
case TextChange(start, _, _) => -start | ||
} | ||
sorted foreach { | ||
case TextChange(start, end, text) => | ||
udoc.replace(start, end-start, text) | ||
} | ||
} | ||
} | ||
|
||
} |
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