Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

rendering: when a string contains \, automatically change to """ #116

Merged
merged 2 commits into from
Sep 5, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion core/src/main/scala/replpp/PPrinter.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package replpp
import replpp.shaded.fansi
import replpp.shaded.pprint
import replpp.shaded.pprint.{PPrinter, Renderer, Result, Tree, Truncated}
import scala.util.matching.Regex

object PPrinter {
private var pprinter: pprint.PPrinter = null
Expand Down
5 changes: 5 additions & 0 deletions core/src/test/scala/replpp/PPrinterTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,11 @@ class PPrinterTests extends AnyWordSpec with Matchers {
)
}

"render strings with string escapes using triple quotes" in {
// TODO suggest as PR in fansi upstream - once it's in, this test can be dropped
PPrinter("""a\b""", nocolors = true) shouldBe " \"\"\"a\\b\"\"\" ".trim
}

"don't error on invalid ansi encodings" in {
val invalidAnsi = Files.readString(ProjectRoot.relativise("core/src/test/resources/invalid-ansi.txt"))
Try {
Expand Down
3 changes: 2 additions & 1 deletion shaded-libs/src/main/scala/replpp/shaded/pprint/Walker.scala
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ abstract class Walker{
case x: Float => Tree.Literal(x.toString + "F")
case x: Double => Tree.Literal(x.toString)
case x: String =>
if (x.exists(c => c == '\n' || c == '\r')) Tree.Literal("\"\"\"" + x + "\"\"\"")
// MP: adapted here: added ` || c == '\\'`
if (x.exists(c => c == '\n' || c == '\r' || c == '\\')) Tree.Literal("\"\"\"" + x + "\"\"\"")
else Tree.Literal(Util.literalize(x, escapeUnicode))

case x: Symbol => Tree.Literal("'" + x.name)
Expand Down
Loading