diff --git a/tests/run-macros/i12163.check b/tests/run-macros/i12163.check new file mode 100644 index 000000000000..c24232089f0f --- /dev/null +++ b/tests/run-macros/i12163.check @@ -0,0 +1,4 @@ +Test +Type +ABC +No label matched: sdofjsdifj diff --git a/tests/run-macros/i12163/Macro_1.scala b/tests/run-macros/i12163/Macro_1.scala new file mode 100644 index 000000000000..8625bd8ad608 --- /dev/null +++ b/tests/run-macros/i12163/Macro_1.scala @@ -0,0 +1,31 @@ +import scala.quoted.* +import scala.util.matching.Regex + +inline def showLabel(inline label: String): String = + ${ showLabelExpr('label) } + + +private def showLabelExpr(label: Expr[String])(using Quotes): Expr[String] = { + val suggestRegex: Regex = "(Type)([a-zA-Z]+)(Mapping)([a-zA-Z]+)".r + val docRegex: Regex = "(Test)(Mapping)([a-zA-Z]+)".r + val simpleRegex: Regex = "([a-zA-Z]+)(Mapping)([a-zA-Z]+)".r + + label.value match { + case Some(docRegex(doc, _, _)) => + Expr(doc) + + case Some(suggestRegex(suggest, suggestType, _, _)) => + Expr(suggest) + + case Some(simpleRegex(docType, _, _)) => + Expr(docType) + + case Some(value) => + Expr(s"No label matched: $value") + // quotes.reflect.report.throwError(s"No label matched: $value") + + case None => + Expr(s"Expected label to be a know string but was: ${label.show}") + // quotes.reflect.report.throwError(s"Expected label to be a know string but was: ${label.show}") + } +} diff --git a/tests/run-macros/i12163/Test_2.scala b/tests/run-macros/i12163/Test_2.scala new file mode 100644 index 000000000000..3af6e91cc489 --- /dev/null +++ b/tests/run-macros/i12163/Test_2.scala @@ -0,0 +1,6 @@ + +@main def Test(): Unit = + println(showLabel("TestMappingDocument")) + println(showLabel("TypeABCMappingDocument")) + println(showLabel("ABCMappingDocument")) + println(showLabel("sdofjsdifj")) \ No newline at end of file