From d45e50c8a6857bd1ea2152c3802496b9417a8c80 Mon Sep 17 00:00:00 2001 From: Liu Fengyun Date: Mon, 1 Apr 2019 17:47:30 +0200 Subject: [PATCH] Add test case for typesafe compile-time stripMargin --- .../reflect-inline/assert_1.scala | 18 ++++++++++++++++++ .../reflect-inline/test_2.scala | 8 ++++++++ 2 files changed, 26 insertions(+) create mode 100644 tests/run-with-compiler/reflect-inline/assert_1.scala create mode 100644 tests/run-with-compiler/reflect-inline/test_2.scala diff --git a/tests/run-with-compiler/reflect-inline/assert_1.scala b/tests/run-with-compiler/reflect-inline/assert_1.scala new file mode 100644 index 000000000000..029b7261dd99 --- /dev/null +++ b/tests/run-with-compiler/reflect-inline/assert_1.scala @@ -0,0 +1,18 @@ +import scala.quoted._ +import scala.tasty._ + +object api { + inline def (inline x: String) strip <: String = + ${ stripImpl(x) } + + private def stripImpl(x: String)(implicit refl: Reflection): Expr[String] = + x.stripMargin.toExpr + + inline def typeChecks(inline x: String): Boolean = + ${ typeChecksImpl(x) } + + private def typeChecksImpl(x: String)(implicit refl: Reflection): Expr[Boolean] = { + import refl._ + if (refl.typing.typeChecks(x)) true.toExpr else false.toExpr + } +} diff --git a/tests/run-with-compiler/reflect-inline/test_2.scala b/tests/run-with-compiler/reflect-inline/test_2.scala new file mode 100644 index 000000000000..e2c09036de0d --- /dev/null +++ b/tests/run-with-compiler/reflect-inline/test_2.scala @@ -0,0 +1,8 @@ +import api._ + +object Test { + def main(args: Array[String]): Unit = { + assert(typeChecks("1 + 1".strip)) + assert(scala.testing.typeChecks("1 + 1".strip)) + } +} \ No newline at end of file