Skip to content

Commit d421955

Browse files
authored
Merge pull request #12165 from dotty-staging/close-#12163
Add regression test
2 parents 6f1846a + 0f9dacc commit d421955

File tree

3 files changed

+41
-0
lines changed

3 files changed

+41
-0
lines changed

tests/run-macros/i12163.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Test
2+
Type
3+
ABC
4+
No label matched: sdofjsdifj

tests/run-macros/i12163/Macro_1.scala

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import scala.quoted.*
2+
import scala.util.matching.Regex
3+
4+
inline def showLabel(inline label: String): String =
5+
${ showLabelExpr('label) }
6+
7+
8+
private def showLabelExpr(label: Expr[String])(using Quotes): Expr[String] = {
9+
val suggestRegex: Regex = "(Type)([a-zA-Z]+)(Mapping)([a-zA-Z]+)".r
10+
val docRegex: Regex = "(Test)(Mapping)([a-zA-Z]+)".r
11+
val simpleRegex: Regex = "([a-zA-Z]+)(Mapping)([a-zA-Z]+)".r
12+
13+
label.value match {
14+
case Some(docRegex(doc, _, _)) =>
15+
Expr(doc)
16+
17+
case Some(suggestRegex(suggest, suggestType, _, _)) =>
18+
Expr(suggest)
19+
20+
case Some(simpleRegex(docType, _, _)) =>
21+
Expr(docType)
22+
23+
case Some(value) =>
24+
Expr(s"No label matched: $value")
25+
// quotes.reflect.report.throwError(s"No label matched: $value")
26+
27+
case None =>
28+
Expr(s"Expected label to be a know string but was: ${label.show}")
29+
// quotes.reflect.report.throwError(s"Expected label to be a know string but was: ${label.show}")
30+
}
31+
}

tests/run-macros/i12163/Test_2.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
2+
@main def Test(): Unit =
3+
println(showLabel("TestMappingDocument"))
4+
println(showLabel("TypeABCMappingDocument"))
5+
println(showLabel("ABCMappingDocument"))
6+
println(showLabel("sdofjsdifj"))

0 commit comments

Comments
 (0)