Skip to content

Commit

Permalink
Fix bug related to escaping single quotes inside strings.
Browse files Browse the repository at this point in the history
Previously, MUnit escaped single quotes inside strings. The escaping is
only needed for single-quote characters.
  • Loading branch information
olafurpg committed Nov 18, 2020
1 parent 9f4fbb9 commit 804af29
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ object Printers {
case x: Printable => x.print(out, indent)
case x: Char =>
out.append('\'')
printChar(x, out)
if (x == '\'') out.append("\\'")
else printChar(x, out)
out.append('\'')
case x: Byte => out.append(x.toString())
case x: Short => out.append(x.toString())
Expand Down Expand Up @@ -190,7 +191,6 @@ object Printers {
private def printChar(c: Char, sb: StringBuilder) =
(c: @switch) match {
case '"' => sb.append("\\\"")
case '\'' => sb.append("\\'")
case '\\' => sb.append("\\\\")
case '\b' => sb.append("\\b")
case '\f' => sb.append("\\f")
Expand Down
10 changes: 10 additions & 0 deletions tests/shared/src/test/scala/munit/PrintersSuite.scala
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ class PrintersSuite extends FunSuite { self =>
'\n',
"'\\n'"
)
check(
"char-single-quote",
'\'',
"'\\''"
)
check(
"string-single-quote",
"'a'",
"\"'a'\""
)
check(
"map",
Map(1 -> 2, 3 -> 4, 5 -> Map(6 -> 7)),
Expand Down

0 comments on commit 804af29

Please sign in to comment.