forked from scala-ide/scalariform
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add an option to add newlines to the end of files.
Fixes scala-ide#113 .
- Loading branch information
Showing
4 changed files
with
61 additions
and
2 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
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
41 changes: 41 additions & 0 deletions
41
scalariform/src/test/scala/scalariform/formatter/NewlineAtEndOfFileFormatterTest.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,41 @@ | ||
package scalariform.formatter | ||
|
||
import scalariform.parser.{CompilationUnit, ScalaParser} | ||
import scalariform.formatter.preferences.{FormattingPreferences, NewlineAtEndOfFile} | ||
|
||
/** Tests that top-level parses add a newline when NewlineAtEndOfFile is set. */ | ||
class NewlineAtEndOfFileFormatterTest extends AbstractFormatterTest { | ||
type Result = CompilationUnit | ||
|
||
// Must parse as a full script to verify the newline formatting. | ||
def parse(parser: ScalaParser) = parser.scriptBody() | ||
|
||
def format(formatter: ScalaFormatter, result: Result) = formatter.format(result)(FormatterState()) | ||
|
||
override val debug = false | ||
|
||
{ | ||
implicit val formattingPreferences = FormattingPreferences.setPreference(NewlineAtEndOfFile, true) | ||
|
||
// No newline; should have one added. | ||
"""import foo.bar | ||
| | ||
|class Foo { | ||
|}""" ==> | ||
"""import foo.bar | ||
| | ||
|class Foo { | ||
|} | ||
|""" | ||
|
||
// Has newline; should stay the same. | ||
"""import foo.bar | ||
|class Foo { | ||
|} | ||
|""" ==> | ||
"""import foo.bar | ||
|class Foo { | ||
|} | ||
|""" | ||
} | ||
} |