You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@groovy.apache.org by su...@apache.org on 2021/07/01 23:17:54 UTC

[groovy] branch GROOVY_2_5_X updated (bced765 -> 7101ec5)

This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a change to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git.


    from bced765  fix for JDK7
     new 3a2a907  GROOVY-10159: Compilation failure: ClassCastException (closes #1604)
     new 7101ec5  GROOVY-10159: minor tweak for the test

The 2 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .../apache/groovy/ast/tools/ExpressionUtils.java   |  3 +-
 .../groovy/ast/tools/ExpressionUtilsTest.groovy    | 78 ++++++++++++++++++++++
 2 files changed, 79 insertions(+), 2 deletions(-)
 create mode 100644 src/test/org/apache/groovy/ast/tools/ExpressionUtilsTest.groovy

[groovy] 02/02: GROOVY-10159: minor tweak for the test

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 7101ec507a02d06dd91a79ec049102e87750ff3a
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri Jul 2 07:17:27 2021 +0800

    GROOVY-10159: minor tweak for the test
---
 .../groovy/ast/tools/ExpressionUtilsTest.groovy    | 42 ++++++++++++++--------
 1 file changed, 27 insertions(+), 15 deletions(-)

diff --git a/src/test/org/apache/groovy/ast/tools/ExpressionUtilsTest.groovy b/src/test/org/apache/groovy/ast/tools/ExpressionUtilsTest.groovy
index 766b7cc..add6f0c 100644
--- a/src/test/org/apache/groovy/ast/tools/ExpressionUtilsTest.groovy
+++ b/src/test/org/apache/groovy/ast/tools/ExpressionUtilsTest.groovy
@@ -18,33 +18,44 @@
  */
 package org.apache.groovy.ast.tools
 
-
-import groovy.transform.AutoFinal
 import org.codehaus.groovy.ast.ClassHelper
 import org.codehaus.groovy.ast.ClassNode
 import org.codehaus.groovy.ast.expr.BinaryExpression
 import org.codehaus.groovy.ast.expr.ConstantExpression
 import org.codehaus.groovy.syntax.Token
 import org.codehaus.groovy.syntax.Types
-import org.junit.Assert
+import org.junit.Test
+
+import static org.junit.Assert.assertEquals
 
 /**
  * Testing expressions of ExpressionUtils.
  */
-@AutoFinal
-final class ExpressionUtilsTest extends GroovyTestCase {
+final class ExpressionUtilsTest {
+    @Test
+    void 'test transformBinaryConstantExpression - null + string'() {
+        ConstantExpression left = new ConstantExpression(null)
+        ConstantExpression right = new ConstantExpression('abc')
+        Token token = new Token(Types.PLUS, '+', 1, 1)
+        BinaryExpression be = new BinaryExpression(left, token, right)
+        ClassNode targetType = ClassHelper.make(String)
+        ConstantExpression actual = ExpressionUtils.transformBinaryConstantExpression(be, targetType)
+        assertEquals('nullabc', actual.value)
+    }
 
-    void 'test transformBinaryConstantExpression - null'() {
-        try {
-            ExpressionUtils.transformBinaryConstantExpression(null, null)
-        } catch(NullPointerException npe) {
-            // Pass
-            return
-        }
-        Assert.fail('Should throw NullPointerException')
+    @Test
+    void 'test transformBinaryConstantExpression - string + null'() {
+        ConstantExpression left = new ConstantExpression('abc')
+        ConstantExpression right = new ConstantExpression(null)
+        Token token = new Token(Types.PLUS, '+', 1, 1)
+        BinaryExpression be = new BinaryExpression(left, token, right)
+        ClassNode targetType = ClassHelper.make(String)
+        ConstantExpression actual = ExpressionUtils.transformBinaryConstantExpression(be, targetType)
+        assertEquals('abcnull', actual.value)
     }
 
-    void 'test transformBinaryConstantExpression - string PLUS string'() {
+    @Test
+    void 'test transformBinaryConstantExpression - string + string'() {
         ConstantExpression left = new ConstantExpression('hello, ')
         ConstantExpression right = new ConstantExpression('world!')
         Token token = new Token(Types.PLUS, '+', 1, 1)
@@ -54,7 +65,8 @@ final class ExpressionUtilsTest extends GroovyTestCase {
         assertEquals('hello, world!', actual.value)
     }
 
-    void 'test transformBinaryConstantExpression - long PLUS long'() {
+    @Test
+    void 'test transformBinaryConstantExpression - long + long'() {
         ConstantExpression left = new ConstantExpression(11111111L)
         ConstantExpression right = new ConstantExpression(11111111L)
         Token token = new Token(Types.PLUS, '+', 1, 1)

[groovy] 01/02: GROOVY-10159: Compilation failure: ClassCastException (closes #1604)

Posted by su...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

sunlan pushed a commit to branch GROOVY_2_5_X
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 3a2a9079a252363c218906c02dd00d2728f78a6f
Author: Dipanjan Bhowmik <di...@lexmark.com>
AuthorDate: Fri Jul 2 07:16:39 2021 +0800

    GROOVY-10159: Compilation failure: ClassCastException (closes #1604)
---
 .../apache/groovy/ast/tools/ExpressionUtils.java   |  3 +-
 .../groovy/ast/tools/ExpressionUtilsTest.groovy    | 66 ++++++++++++++++++++++
 2 files changed, 67 insertions(+), 2 deletions(-)

diff --git a/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java b/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
index 4aa67a5..8c40a17 100644
--- a/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
+++ b/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
@@ -83,8 +83,7 @@ public final class ExpressionUtils {
                 Expression left = transformInlineConstants(be.getLeftExpression(), targetType);
                 Expression right = transformInlineConstants(be.getRightExpression(), targetType);
                 if (left instanceof ConstantExpression && right instanceof ConstantExpression) {
-                    return configure(be, new ConstantExpression((String) ((ConstantExpression) left).getValue() +
-                            ((ConstantExpression) right).getValue()));
+                    return configure(be, new ConstantExpression(String.valueOf(((ConstantExpression) left).getValue()) + ((ConstantExpression) right).getValue()));
                 }
             }
         } else if (isNumberOrArrayOfNumber(wrapperType, false)) {
diff --git a/src/test/org/apache/groovy/ast/tools/ExpressionUtilsTest.groovy b/src/test/org/apache/groovy/ast/tools/ExpressionUtilsTest.groovy
new file mode 100644
index 0000000..766b7cc
--- /dev/null
+++ b/src/test/org/apache/groovy/ast/tools/ExpressionUtilsTest.groovy
@@ -0,0 +1,66 @@
+/*
+ *  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.apache.groovy.ast.tools
+
+
+import groovy.transform.AutoFinal
+import org.codehaus.groovy.ast.ClassHelper
+import org.codehaus.groovy.ast.ClassNode
+import org.codehaus.groovy.ast.expr.BinaryExpression
+import org.codehaus.groovy.ast.expr.ConstantExpression
+import org.codehaus.groovy.syntax.Token
+import org.codehaus.groovy.syntax.Types
+import org.junit.Assert
+
+/**
+ * Testing expressions of ExpressionUtils.
+ */
+@AutoFinal
+final class ExpressionUtilsTest extends GroovyTestCase {
+
+    void 'test transformBinaryConstantExpression - null'() {
+        try {
+            ExpressionUtils.transformBinaryConstantExpression(null, null)
+        } catch(NullPointerException npe) {
+            // Pass
+            return
+        }
+        Assert.fail('Should throw NullPointerException')
+    }
+
+    void 'test transformBinaryConstantExpression - string PLUS string'() {
+        ConstantExpression left = new ConstantExpression('hello, ')
+        ConstantExpression right = new ConstantExpression('world!')
+        Token token = new Token(Types.PLUS, '+', 1, 1)
+        BinaryExpression be = new BinaryExpression(left, token, right)
+        ClassNode targetType = ClassHelper.make(String)
+        ConstantExpression actual = ExpressionUtils.transformBinaryConstantExpression(be, targetType)
+        assertEquals('hello, world!', actual.value)
+    }
+
+    void 'test transformBinaryConstantExpression - long PLUS long'() {
+        ConstantExpression left = new ConstantExpression(11111111L)
+        ConstantExpression right = new ConstantExpression(11111111L)
+        Token token = new Token(Types.PLUS, '+', 1, 1)
+        BinaryExpression be = new BinaryExpression(left, token, right)
+        ClassNode targetType = ClassHelper.make(Long)
+        ConstantExpression actual = ExpressionUtils.transformBinaryConstantExpression(be, targetType)
+        assertEquals(22222222L, actual.value)
+    }
+}
\ No newline at end of file