diff options
author | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-01-17 14:39:30 -0800 |
---|---|---|
committer | Adriaan Moors <adriaan.moors@typesafe.com> | 2014-01-17 14:39:30 -0800 |
commit | 7c0fd124a636bb0dcca236d5aaf7e799c40d6104 (patch) | |
tree | 9c0dac258c7a6dc5aa7c5690d63e5aaa16f99b53 | |
parent | 03110889ddc33ada04981727bb5715c511eddc42 (diff) | |
parent | 06bae51b0767e5bfcc7968448c60659523dd4370 (diff) | |
download | scala-7c0fd124a636bb0dcca236d5aaf7e799c40d6104.tar.gz scala-7c0fd124a636bb0dcca236d5aaf7e799c40d6104.tar.bz2 scala-7c0fd124a636bb0dcca236d5aaf7e799c40d6104.zip |
Merge pull request #3377 from VladimirNik/sprinter-eol-fix
Fix EOL-printing in Printers test suite
-rw-r--r-- | src/reflect/scala/reflect/internal/Printers.scala | 12 | ||||
-rw-r--r-- | test/junit/scala/reflect/internal/PrintersTest.scala | 9 |
2 files changed, 14 insertions, 7 deletions
diff --git a/src/reflect/scala/reflect/internal/Printers.scala b/src/reflect/scala/reflect/internal/Printers.scala index 8b72f98e4d..519d1047a6 100644 --- a/src/reflect/scala/reflect/internal/Printers.scala +++ b/src/reflect/scala/reflect/internal/Printers.scala @@ -735,7 +735,8 @@ trait Printers extends api.Printers { self: SymbolTable => println() }; case _ => - printPackageDef(pd, "\n") + val separator = scala.util.Properties.lineSeparator + printPackageDef(pd, separator) } case md @ ModuleDef(mods, name, impl) => @@ -944,15 +945,16 @@ trait Printers extends api.Printers { self: SymbolTable => } case l @ Literal(x) => + import Chars.LF x match { case Constant(v: String) if { val strValue = x.stringValue - strValue.contains("\n") && strValue.contains("\"\"\"") && strValue.size > 1 + strValue.contains(LF) && strValue.contains("\"\"\"") && strValue.size > 1 } => - val splitValue = x.stringValue.split('\n'.toString).toList - val multilineStringValue = if (x.stringValue.endsWith("\n")) splitValue :+ "" else splitValue + val splitValue = x.stringValue.split(s"$LF").toList + val multilineStringValue = if (x.stringValue.endsWith(s"$LF")) splitValue :+ "" else splitValue val trQuotes = "\"\"\"" - print(trQuotes); printSeq(multilineStringValue) { print(_) } { print("\n") }; print(trQuotes) + print(trQuotes); printSeq(multilineStringValue) { print(_) } { print(LF) }; print(trQuotes) case _ => // processing Float constants val printValue = x.escapedStringValue + (if (x.value.isInstanceOf[Float]) "F" else "") diff --git a/test/junit/scala/reflect/internal/PrintersTest.scala b/test/junit/scala/reflect/internal/PrintersTest.scala index 53ea3fd8a3..a08a29a9d1 100644 --- a/test/junit/scala/reflect/internal/PrintersTest.scala +++ b/test/junit/scala/reflect/internal/PrintersTest.scala @@ -19,14 +19,19 @@ class PrintersTest extends BasePrintTests object PrinterHelper { val toolbox = cm.mkToolBox() def assertPrintedCode(code: String, tree: Tree = EmptyTree) = { + def processEOL(resultCode: String) = { + import scala.reflect.internal.Chars._ + resultCode.replaceAll(s"$CR$LF", s"$LF").replace(CR, LF) + } + val toolboxTree = try{ toolbox.parse(code) } catch { case e:scala.tools.reflect.ToolBoxError => throw new Exception(e.getMessage + ": " + code) } - if (tree ne EmptyTree) assertEquals("using quasiquote or given tree"+"\n", code.trim, showCode(tree)) - else assertEquals("using toolbox parser", code.trim, showCode(toolboxTree)) + if (tree ne EmptyTree) assertEquals("using quasiquote or given tree"+"\n", code.trim, processEOL(showCode(tree))) + else assertEquals("using toolbox parser", code.trim, processEOL(showCode(toolboxTree))) } implicit class StrContextStripMarginOps(val stringContext: StringContext) extends util.StripMarginInterpolator |