From 75760787a38087144e735d43ef5e5cef020c6e40 Mon Sep 17 00:00:00 2001 From: Philipp Ossler Date: Fri, 12 May 2023 06:08:09 +0200 Subject: [PATCH 1/2] build: Ignore inner methods for Clirr Clirr reports a false positive if an inner method is changed. Adjust the configuration of the Clirr plugin to ignore these errors. (cherry picked from commit f9fde28020d70bd1cb2e2fb828443e4b8cc4f841) (cherry picked from commit 0aade7c9cbda9e240fba0bdb13b2832ca225c0e3) --- pom.xml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/pom.xml b/pom.xml index 57ed82618..a96447da3 100644 --- a/pom.xml +++ b/pom.xml @@ -281,6 +281,11 @@ 7004 * $anonfun*(*) + + org/camunda/feel/** + 7002 + * $anonfun*(*) + org/camunda/feel/** From 33f0222d5732e5006b531e677440bc59685043f4 Mon Sep 17 00:00:00 2001 From: sfrick Date: Tue, 9 May 2023 11:35:28 +0200 Subject: [PATCH 2/2] fix(builtin-function): fix string conversion of years-months-durations * add tests for string conversion of zero-length years-months-duration * add tests for string conversion of negative years-months-duration (cherry picked from commit 38c8e383afd6d087b73b1c54b17a227a971666a5) (cherry picked from commit 9b5614c951c81c9c7469b5f6b0521cb01f314025) --- .../builtin/ConversionBuiltinFunctions.scala | 2 +- .../org/camunda/feel/syntaxtree/Val.scala | 22 +++++++++++++++++++ .../BuiltinConversionFunctionsTest.scala | 12 ++++++++++ .../DateTimeDurationPropertiesTest.scala | 2 +- 4 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/main/scala/org/camunda/feel/impl/builtin/ConversionBuiltinFunctions.scala b/src/main/scala/org/camunda/feel/impl/builtin/ConversionBuiltinFunctions.scala index 4ed839e69..d44e76400 100644 --- a/src/main/scala/org/camunda/feel/impl/builtin/ConversionBuiltinFunctions.scala +++ b/src/main/scala/org/camunda/feel/impl/builtin/ConversionBuiltinFunctions.scala @@ -237,7 +237,7 @@ object ConversionBuiltinFunctions { .replaceAll("$1$3") ValString(dateTimeWithOffsetOrZoneId) } - case List(ValYearMonthDuration(from)) => ValString(from.toString) + case List(duration: ValYearMonthDuration) => ValString(duration.toString) case List(duration: ValDayTimeDuration) => ValString(duration.toString) } ) diff --git a/src/main/scala/org/camunda/feel/syntaxtree/Val.scala b/src/main/scala/org/camunda/feel/syntaxtree/Val.scala index b998415f5..37e2ec77e 100644 --- a/src/main/scala/org/camunda/feel/syntaxtree/Val.scala +++ b/src/main/scala/org/camunda/feel/syntaxtree/Val.scala @@ -171,6 +171,28 @@ case class ValDateTime(value: DateTime) extends Val { } case class ValYearMonthDuration(value: YearMonthDuration) extends Val { + + override def toString: String = { + def makeString(sign: String, year: Long, month: Long): String = { + val y = Option(year).filterNot(_ == 0).map(_ + "Y").getOrElse("") + val m = Option(month).filterNot(_ == 0).map(_ + "M").getOrElse("") + + val stringBuilder = new StringBuilder("") + stringBuilder.append(sign).append("P").append(y).append(m) + stringBuilder.toString() + } + + val year = value.getYears + val month = value.getMonths % 12 + + if (year == 0 && month == 0) + "P0Y" + else if (year <= 0 && month <= 0) + makeString("-", -year, -month) + else + makeString("", year, month) + } + override val properties: Map[String, Val] = Map( "years" -> ValNumber(value.getYears), "months" -> ValNumber(value.getMonths) diff --git a/src/test/scala/org/camunda/feel/impl/builtin/BuiltinConversionFunctionsTest.scala b/src/test/scala/org/camunda/feel/impl/builtin/BuiltinConversionFunctionsTest.scala index 478870e6a..3469557df 100644 --- a/src/test/scala/org/camunda/feel/impl/builtin/BuiltinConversionFunctionsTest.scala +++ b/src/test/scala/org/camunda/feel/impl/builtin/BuiltinConversionFunctionsTest.scala @@ -217,6 +217,18 @@ class BuiltinConversionFunctionsTest eval(""" string(@"P1DT2H3M4S") """) should be(ValString("P1DT2H3M4S")) } + it should "convert zero-length years-months-duration" in { + + eval(""" string(@"P0Y") """) should be(ValString("P0Y")) + eval(""" string(@"-P0M") """) should be(ValString("P0Y")) + eval(""" string(@"P0Y0M") """) should be(ValString("P0Y")) + } + it should "convert negative years-months-duration" in { + + eval(""" string(@"-P1Y") """) should be(ValString("-P1Y")) + eval(""" string(@"-P5M") """) should be(ValString("-P5M")) + eval(""" string(@"-P3Y1M") """) should be(ValString("-P3Y1M")) + } it should "convert years-months-duration" in { eval(""" string(@"P1Y") """) should be(ValString("P1Y")) diff --git a/src/test/scala/org/camunda/feel/impl/interpreter/DateTimeDurationPropertiesTest.scala b/src/test/scala/org/camunda/feel/impl/interpreter/DateTimeDurationPropertiesTest.scala index 465ad8a45..27df06fbe 100644 --- a/src/test/scala/org/camunda/feel/impl/interpreter/DateTimeDurationPropertiesTest.scala +++ b/src/test/scala/org/camunda/feel/impl/interpreter/DateTimeDurationPropertiesTest.scala @@ -295,7 +295,7 @@ class DateTimeDurationPropertiesTest result shouldBe a[ValError] result.asInstanceOf[ValError].error should startWith( - "No property found with name 'x' of value 'ValYearMonthDuration(P2Y3M)'. Available properties:") + "No property found with name 'x' of value 'P2Y3M'. Available properties:") } it should "has properties with @-notation" in {