Skip to content

Commit

Permalink
Avoid missing interpolator in display string
Browse files Browse the repository at this point in the history
  • Loading branch information
som-snytt committed May 15, 2024
1 parent e231592 commit cd4b2f0
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ val scala211 = "2.11.12"
val scala212 = "2.12.19"
val scala213 = "2.13.14"
val scala3 = "3.1.2"
val scalaFull = Seq(scala213, scala212, scala211, scala3)
val scalaFull = Seq(scala213, scala212, /*scala211,*/ scala3)
ThisBuild / scalaVersion := scala213
Global / semanticdbEnabled := true
Global / semanticdbVersion := "4.9.3"
Expand Down
4 changes: 2 additions & 2 deletions project/plugins.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
val scalaJSVersion =
Option(System.getenv("SCALAJS_VERSION")).getOrElse("1.12.0")
Option(System.getenv("SCALAJS_VERSION")).getOrElse("1.16.0")
val scalaNativeVersion =
Option(System.getenv("SCALANATIVE_VERSION")).getOrElse("0.4.9")
Option(System.getenv("SCALANATIVE_VERSION")).getOrElse("0.5.1")

addSbtPlugin("com.github.sbt" % "sbt-ci-release" % "1.5.12")
addSbtPlugin("com.eed3si9n" % "sbt-projectmatrix" % "0.10.0")
Expand Down
12 changes: 11 additions & 1 deletion src/main/scala-2/com/eed3si9n/expecty/RecorderMacro.scala
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,19 @@ Instrumented AST: ${showRaw(instrumented)}")
"""
)

// to avoid missing interpolator lint, turn "a$b" into "a" + "$" + "b"
val cleanSource = {
val N = source.length - 1
source.indexOf('$') match {
case -1 | N => q"$source"
case _ =>
val parts = source.split('$').toList
parts.tail.foldLeft(q"${parts.head}")((t, s) => q"""$t + "$$" + $s""")
}
}
Apply(
Select(Ident(termName(context)("$com_eed3si9n_expecty_recorderRuntime")), termName(context)("recordExpression")),
List(q"$source", q"$ast", instrumented, getSourceLocation)
List(cleanSource, q"$ast", instrumented, getSourceLocation)
)
}

Expand Down

0 comments on commit cd4b2f0

Please sign in to comment.