Skip to content

Commit

Permalink
Problem with EOL in tests for Printers is fixed
Browse files Browse the repository at this point in the history
  • Loading branch information
VladimirNik committed Jan 17, 2014
1 parent 695b9e1 commit 06bae51
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 7 deletions.
12 changes: 7 additions & 5 deletions src/reflect/scala/reflect/internal/Printers.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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 "")
Expand Down
9 changes: 7 additions & 2 deletions test/junit/scala/reflect/internal/PrintersTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 06bae51

Please sign in to comment.