ChinchuAjith commented on code in PR #6632: URL: https://github.com/apache/incubator-kie-drools/pull/6632#discussion_r3108333512
########## kie-dmn/kie-dmn-feel/src/test/java/org/kie/dmn/feel/lang/ast/dialectHandlers/BFEELDialectHandlerTest.java: ########## @@ -0,0 +1,235 @@ +/* + * 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(); + } + + @Test + void testAddOperations() { + // String concatenation with type coercion + assertThat(handler.executeAdd("Hello", "World", ctx)).isEqualTo("HelloWorld"); + assertThat(handler.executeAdd("Hello", 123, ctx)).isEqualTo("Hello123"); + assertThat(handler.executeAdd("Hello", null, ctx)).isEqualTo("Hello"); + + // Numbers + assertThat(handler.executeAdd(10, 20, ctx)).isEqualTo(new BigDecimal("30")); + assertThat(handler.executeAdd(10, null, ctx)).isEqualTo(10); + + // Date operations - returns number instead of null + assertThat(handler.executeAdd(LocalDate.of(2024, 1, 1), 5, ctx)).isEqualTo(5); Review Comment: I understand the concern @gitgabrio Based on the further analysis, this is the implementation we are doing currently Reordered and corrected the addition operations in getAddOperations() method to comply with BFEEL Section 11.9 specification: **Key Fix: Number operations now take precedence over string concatenation, following the BFEEL Table 11.9 precedence rules.** **Precedence:** 1. Date + Number operations → Returns the number * BFEEL Section 11.9, when one operand is a number, the non-number value (date) is converted to a number using the number() function * In BFEEL, number(date) returns 0 (per Section 11.3) * Therefore: 0 + 5 = 5, so we return the number operand 2. Number + Date operations → Returns the number * Same logic: 5 + 0 = 5, so we return the number operand 3. Number + null operations → Returns the number 4. null + Number operations → Returns the number 5. String concatenation → Only applies when no number operands are present -- 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]
