From 1f7160c95cd7b8827de9ac9db4215516664fce54 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Pa=C5=82ka?= Date: Tue, 13 Jul 2021 16:00:49 +0200 Subject: [PATCH] Regression tests for quoted patterns for NaN and floating point zeros --- tests/neg-macros/i13033/Macro_1.scala | 12 ++++++++++++ tests/neg-macros/i13033/Test_2.scala | 3 +++ tests/run-macros/i13033.check | 3 +++ tests/run-macros/i13033/Macro_1.scala | 17 +++++++++++++++++ tests/run-macros/i13033/Test_2.scala | 4 ++++ 5 files changed, 39 insertions(+) create mode 100644 tests/neg-macros/i13033/Macro_1.scala create mode 100644 tests/neg-macros/i13033/Test_2.scala create mode 100644 tests/run-macros/i13033.check create mode 100644 tests/run-macros/i13033/Macro_1.scala create mode 100644 tests/run-macros/i13033/Test_2.scala diff --git a/tests/neg-macros/i13033/Macro_1.scala b/tests/neg-macros/i13033/Macro_1.scala new file mode 100644 index 000000000000..788d82ad4c9b --- /dev/null +++ b/tests/neg-macros/i13033/Macro_1.scala @@ -0,0 +1,12 @@ +import scala.quoted.* + +object Macro: + def positiveImpl(using Quotes): Expr[Any] = + '{ 0.0 } match + case '{ -0.0 } => '{1} + inline def positive: Any = ${positiveImpl} + + def negativeImpl(using Quotes): Expr[Any] = + '{ -0.0 } match + case '{ 0.0 } => '{-1} + inline def negative: Any = ${negativeImpl} diff --git a/tests/neg-macros/i13033/Test_2.scala b/tests/neg-macros/i13033/Test_2.scala new file mode 100644 index 000000000000..a5e2edc39ea3 --- /dev/null +++ b/tests/neg-macros/i13033/Test_2.scala @@ -0,0 +1,3 @@ +@main def test(): Unit = + println(Macro.positive) // error + println(Macro.negative) // error diff --git a/tests/run-macros/i13033.check b/tests/run-macros/i13033.check new file mode 100644 index 000000000000..d7e52d192eb1 --- /dev/null +++ b/tests/run-macros/i13033.check @@ -0,0 +1,3 @@ +0 +1 +-1 diff --git a/tests/run-macros/i13033/Macro_1.scala b/tests/run-macros/i13033/Macro_1.scala new file mode 100644 index 000000000000..8f2c040bad5b --- /dev/null +++ b/tests/run-macros/i13033/Macro_1.scala @@ -0,0 +1,17 @@ +import scala.quoted.* + +object Macro: + def nanImpl(using Quotes): Expr[Any] = + '{ Double.NaN } match + case '{ Double.NaN } => '{0} + inline def nan: Any = ${nanImpl} + + def positiveImpl(using Quotes): Expr[Any] = + '{ 0.0 } match + case '{ 0.0 } => '{1} + inline def positive: Any = ${positiveImpl} + + def negativeImpl(using Quotes): Expr[Any] = + '{ -0.0 } match + case '{ -0.0 } => '{-1} + inline def negative: Any = ${negativeImpl} diff --git a/tests/run-macros/i13033/Test_2.scala b/tests/run-macros/i13033/Test_2.scala new file mode 100644 index 000000000000..f972c8f67555 --- /dev/null +++ b/tests/run-macros/i13033/Test_2.scala @@ -0,0 +1,4 @@ +@main def Test(): Unit = + println(Macro.nan) + println(Macro.positive) + println(Macro.negative)