summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSom Snytt <som.snytt@gmail.com>2016-06-16 00:43:51 -0700
committerSom Snytt <som.snytt@gmail.com>2016-06-16 00:43:51 -0700
commit8eaa53d57c8d3346e03ccde7b7d4c4c8103d9253 (patch)
tree7810a5f3c918471e071a7130e6d9323a5f03d8fe
parent79e7334f93da4717ee846f74e48ab53533e6756d (diff)
downloadscala-8eaa53d57c8d3346e03ccde7b7d4c4c8103d9253.tar.gz
scala-8eaa53d57c8d3346e03ccde7b7d4c4c8103d9253.tar.bz2
scala-8eaa53d57c8d3346e03ccde7b7d4c4c8103d9253.zip
Avoid triple-quoting triple quotes
The boolean test for triples was inadvertently flipped. Adds test for pretty printed multiline strings
-rw-r--r--src/reflect/scala/reflect/internal/Printers.scala2
-rw-r--r--test/junit/scala/reflect/internal/PrintersTest.scala8
2 files changed, 9 insertions, 1 deletions
diff --git a/src/reflect/scala/reflect/internal/Printers.scala b/src/reflect/scala/reflect/internal/Printers.scala
index 37b99c4345..4ad34ff8c7 100644
--- a/src/reflect/scala/reflect/internal/Printers.scala
+++ b/src/reflect/scala/reflect/internal/Printers.scala
@@ -1050,7 +1050,7 @@ trait Printers extends api.Printers { self: SymbolTable =>
x match {
case Constant(v: String) if {
val strValue = x.stringValue
- strValue.contains(LF) && strValue.contains("\"\"\"") && strValue.size > 1
+ strValue.contains(LF) && !strValue.contains("\"\"\"") && strValue.size > 1
} =>
val splitValue = x.stringValue.split(s"$LF").toList
val multilineStringValue = if (x.stringValue.endsWith(s"$LF")) splitValue :+ "" else splitValue
diff --git a/test/junit/scala/reflect/internal/PrintersTest.scala b/test/junit/scala/reflect/internal/PrintersTest.scala
index 2305e7ea50..916f21adc8 100644
--- a/test/junit/scala/reflect/internal/PrintersTest.scala
+++ b/test/junit/scala/reflect/internal/PrintersTest.scala
@@ -79,6 +79,14 @@ class BasePrintTest {
@Test def testConstantLong = assertTreeCode(Literal(Constant(42l)))("42L")
+ @Test def testConstantMultiline = assertTreeCode(Literal(Constant("hello\nworld")))("\"\"\"hello\nworld\"\"\"")
+
+ val sq = "\""
+ val teq = "\\\"" * 3
+ val tq = "\"" * 3
+
+ @Test def testConstantEmbeddedTriple = assertTreeCode(Literal(Constant(s"${tq}hello${tq}\nworld")))(s"${sq}${teq}hello${teq}\\nworld${sq}")
+
@Test def testOpExpr = assertPrintedCode("(5).+(4)", checkTypedTree = false)
@Test def testName1 = assertPrintedCode("class test")