Skip to content

Commit aa59bef

Browse files
Merge pull request #6223 from dotty-staging/add-xml-str-interpol-regression-test
Add regression test
2 parents 5b0a7ce + 0826de4 commit aa59bef

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import scala.quoted._
2+
import scala.quoted.autolift._
3+
import scala.tasty.Reflection
4+
5+
import scala.language.implicitConversions
6+
7+
object XmlQuote {
8+
9+
implicit object SCOps {
10+
inline def (ctx: => StringContext) xml (args: => (given Scope => Any)*) given Scope: String =
11+
${XmlQuote.impl('ctx, 'args, '{implicitly[Scope]})}
12+
}
13+
14+
private def impl(receiver: Expr[StringContext], args: Expr[Seq[given Scope => Any]], scope: Expr[Scope]): Expr[String] = '{
15+
$receiver.s($args.map(_ given $scope.inner): _*)
16+
}
17+
}
18+
19+
case class Scope(name: String) {
20+
def inner: Scope = Scope(name + "+")
21+
}
22+
23+
object Scope {
24+
implicit def topScope: Scope = Scope("top")
25+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import XmlQuote._
2+
3+
object Test {
4+
def main(args: Array[String]): Unit = {
5+
assert(xml"Hello ${implicitly[Scope]} world!" == "Hello Scope(top+) world!")
6+
assert(xml"Hello ${ xml"world ${implicitly[Scope] + " " + xml"${implicitly[Scope]}"}" }!" ==
7+
"Hello world Scope(top++) Scope(top+++)!")
8+
}
9+
}

0 commit comments

Comments
 (0)