From 8eaa53d57c8d3346e03ccde7b7d4c4c8103d9253 Mon Sep 17 00:00:00 2001 From: Som Snytt Date: Thu, 16 Jun 2016 00:43:51 -0700 Subject: Avoid triple-quoting triple quotes The boolean test for triples was inadvertently flipped. Adds test for pretty printed multiline strings --- src/reflect/scala/reflect/internal/Printers.scala | 2 +- test/junit/scala/reflect/internal/PrintersTest.scala | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) 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") -- cgit v1.2.3