Copilot commented on code in PR #6632:
URL: 
https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3147439827


##########
kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java:
##########
@@ -0,0 +1,294 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.kie.dmn.feel.lang.ast.dialectHandlers;
+
+import java.math.BigDecimal;
+import java.time.Duration;
+import java.time.LocalDate;
+import java.time.Period;
+
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.kie.dmn.feel.lang.EvaluationContext;
+import org.kie.dmn.feel.lang.types.impl.ComparablePeriod;
+import org.kie.dmn.feel.util.EvaluationContextTestUtil;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * Unit tests for BFEELDialectHandler - BFEEL uses type coercion and returns 
default values
+ */
+class BFEELDialectHandlerTest {
+
+    private BFEELDialectHandler handler;
+    private EvaluationContext ctx;
+
+    @BeforeEach
+    void setUp() {
+        handler = new BFEELDialectHandler();
+        ctx = EvaluationContextTestUtil.newEmptyEvaluationContext();
+    }

Review Comment:
   BFEELDialectHandler behavior depends on ctx.getFEELDialect() (e.g., 
DefaultDialectHandler/InfixExecutorUtils apply BFEEL-specific coercions and 
defaults based on the dialect). This test sets up an EvaluationContext that 
defaults to FEEL, so the assertions may not reflect real BFEEL execution via 
DialectHandlerFactory. Please initialize the context with FEELDialect.BFEEL 
(e.g., EvaluationContextImpl(..., FEELDialect.BFEEL) or a mock returning BFEEL).



##########
kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandler.java:
##########
@@ -60,20 +80,64 @@ public Map<CheckedPredicate, BiFunction<Object, Object, 
Object>> getAddOperation
                     return leftNum + rightNum;
                 });
 
-        // date + number → return the number
+        // Row 2: NUMBER - date + number → convert date to 0, then add: 0 + 
number = number
+        // Since 0 + number = number, we return the number operand directly
         map.put(
                 new CheckedPredicate((left, right) -> left instanceof 
LocalDate && right instanceof Number, false),
                 (left, right) -> right);
+        
+        // Row 2: NUMBER - number + date → convert date to 0, then add: number 
+ 0 = number
+        // Since number + 0 = number, we return the number operand directly
         map.put(
                 new CheckedPredicate((left, right) -> left instanceof Number 
&& right instanceof LocalDate, false),
                 (left, right) -> left);
 
-        // Number + null → number
+        // Row 2: NUMBER - duration + number → convert duration to seconds, 
then add
+        map.put(
+                new CheckedPredicate((left, right) -> left instanceof Duration 
&& right instanceof Number, false),
+                (left, right) -> {
+                    BigDecimal seconds = getBigDecimalOrNull(((Duration) 
left).getSeconds());
+                    BigDecimal rightNum = getBigDecimalOrNull(right);
+                    if (seconds == null || rightNum == null) return rightNum 
!= null ? rightNum : BigDecimal.ZERO;
+                    return seconds.add(rightNum, MathContext.DECIMAL128);
+                });
+
+        // Row 2: NUMBER - number + duration → convert duration to seconds, 
then add
+        map.put(
+                new CheckedPredicate((left, right) -> left instanceof Number 
&& right instanceof Duration, false),
+                (left, right) -> {
+                    BigDecimal leftNum = getBigDecimalOrNull(left);
+                    BigDecimal seconds = getBigDecimalOrNull(((Duration) 
right).getSeconds());
+                    if (leftNum == null || seconds == null) return leftNum != 
null ? leftNum : BigDecimal.ZERO;
+                    return leftNum.add(seconds, MathContext.DECIMAL128);
+                });
+
+        // Row 2: NUMBER - period + number → convert period to months, then add
+        map.put(
+                new CheckedPredicate((left, right) -> left instanceof 
ChronoPeriod && right instanceof Number, false),
+                (left, right) -> {
+                    BigDecimal months = 
getBigDecimalOrNull(ComparablePeriod.toTotalMonths((ChronoPeriod) left));
+                    BigDecimal rightNum = getBigDecimalOrNull(right);
+                    if (months == null || rightNum == null) return rightNum != 
null ? rightNum : BigDecimal.ZERO;
+                    return months.add(rightNum, MathContext.DECIMAL128);
+                });
+
+        // Row 2: NUMBER - number + period → convert period to months, then add
+        map.put(
+                new CheckedPredicate((left, right) -> left instanceof Number 
&& right instanceof ChronoPeriod, false),
+                (left, right) -> {
+                    BigDecimal leftNum = getBigDecimalOrNull(left);
+                    BigDecimal months = 
getBigDecimalOrNull(ComparablePeriod.toTotalMonths((ChronoPeriod) right));
+                    if (leftNum == null || months == null) return leftNum != 
null ? leftNum : BigDecimal.ZERO;
+                    return leftNum.add(months, MathContext.DECIMAL128);
+                });

Review Comment:
   The PR description states this change is adding unit tests, but this file 
introduces/changes runtime semantics for BFEEL (addition coercions, pow 
behavior, mult/div rules). Please either update the PR description to 
explicitly call out these behavior changes and link them to the tracked 
issue/spec, or split the implementation changes into a separate PR so the 
test-only PR remains scoped to tests.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to