Skip to content

Add regression test #12165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions tests/run-macros/i12163.check
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Test
Type
ABC
No label matched: sdofjsdifj
31 changes: 31 additions & 0 deletions tests/run-macros/i12163/Macro_1.scala
Original file line number Diff line number Diff line change
@@ -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}")
}
}
6 changes: 6 additions & 0 deletions tests/run-macros/i12163/Test_2.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@

@main def Test(): Unit =
println(showLabel("TestMappingDocument"))
println(showLabel("TypeABCMappingDocument"))
println(showLabel("ABCMappingDocument"))
println(showLabel("sdofjsdifj"))