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.
Merge pull request scala-ide#191 from jkinkead/eol_at_eof
Add an option to add newlines to the end of files.
- Loading branch information
Showing
4 changed files
with
85 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
65 changes: 65 additions & 0 deletions
65
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,65 @@ | ||
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 SettingOn { | ||
|}""" ==> | ||
"""import foo.bar | ||
| | ||
|class SettingOn { | ||
|} | ||
|""" | ||
|
||
// Has newline; should stay the same. | ||
"""import foo.bar | ||
|class SettingOn { | ||
|} | ||
|""" ==> | ||
"""import foo.bar | ||
|class SettingOn { | ||
|} | ||
|""" | ||
} | ||
|
||
{ | ||
implicit val formattingPreferences = FormattingPreferences.setPreference(NewlineAtEndOfFile, false) | ||
|
||
// No newline; should stay the same. | ||
"""import foo.bar | ||
| | ||
|class SettingOff { | ||
|}""" ==> | ||
"""import foo.bar | ||
| | ||
|class SettingOff { | ||
|}""" | ||
|
||
// Has newline; should stay the same (preference off doesn't strip newlines that exist). | ||
"""import foo.bar | ||
|class SettingOff { | ||
|} | ||
|""" ==> | ||
"""import foo.bar | ||
|class SettingOff { | ||
|} | ||
|""" | ||
} | ||
} |