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 22:49:40 UTC

[groovy] branch master updated (9b90016 -> e7bf14f)

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

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


    from 9b90016  GROOVY-10160: Highlight source code in the AST browser smartly
     new 1907fea  GROOVY-10159: Compilation failure: ClassCastException (closes #1604)
     new e7bf14f  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   |  2 +-
 .../groovy/ast/tools/ExpressionUtilsTest.groovy    | 78 ++++++++++++++++++++++
 2 files changed, 79 insertions(+), 1 deletion(-)
 create mode 100644 src/test/org/apache/groovy/ast/tools/ExpressionUtilsTest.groovy

[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 master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit 1907fea95b79e523f94cd99eaa601c66666c047e
Author: Dipanjan Bhowmik <di...@lexmark.com>
AuthorDate: Fri Jul 2 06:32:13 2021 +0800

    GROOVY-10159: Compilation failure: ClassCastException (closes #1604)
---
 .../apache/groovy/ast/tools/ExpressionUtils.java   |  2 +-
 .../groovy/ast/tools/ExpressionUtilsTest.groovy    | 72 ++++++++++++++++++++++
 2 files changed, 73 insertions(+), 1 deletion(-)

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 aad536c..bb9790c 100644
--- a/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
+++ b/src/main/java/org/apache/groovy/ast/tools/ExpressionUtils.java
@@ -84,7 +84,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..2f6b5f7
--- /dev/null
+++ b/src/test/org/apache/groovy/ast/tools/ExpressionUtilsTest.groovy
@@ -0,0 +1,72 @@
+/*
+ *  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.test.GroovyTestCase
+import groovy.test.NotYetImplemented
+import groovy.transform.AutoFinal
+import org.apache.groovy.parser.antlr4.TestUtils
+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.control.CompilationUnit
+import org.codehaus.groovy.control.Phases
+import org.codehaus.groovy.syntax.Token
+import org.codehaus.groovy.syntax.Types
+import org.junit.Assert
+
+import static org.apache.groovy.parser.antlr4.util.ASTComparatorCategory.LOCATION_IGNORE_LIST
+
+/**
+ * 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)
+    }
+}

[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 master
in repository https://gitbox.apache.org/repos/asf/groovy.git

commit e7bf14ff3a7896c30cafa7fe481c18b68080beba
Author: Daniel Sun <su...@apache.org>
AuthorDate: Fri Jul 2 06:36:19 2021 +0800

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

diff --git a/src/test/org/apache/groovy/ast/tools/ExpressionUtilsTest.groovy b/src/test/org/apache/groovy/ast/tools/ExpressionUtilsTest.groovy
index 2f6b5f7..4d8238d 100644
--- a/src/test/org/apache/groovy/ast/tools/ExpressionUtilsTest.groovy
+++ b/src/test/org/apache/groovy/ast/tools/ExpressionUtilsTest.groovy
@@ -18,39 +18,44 @@
  */
 package org.apache.groovy.ast.tools
 
-import groovy.test.GroovyTestCase
-import groovy.test.NotYetImplemented
-import groovy.transform.AutoFinal
-import org.apache.groovy.parser.antlr4.TestUtils
 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.control.CompilationUnit
-import org.codehaus.groovy.control.Phases
 import org.codehaus.groovy.syntax.Token
 import org.codehaus.groovy.syntax.Types
-import org.junit.Assert
+import org.junit.Test
 
-import static org.apache.groovy.parser.antlr4.util.ASTComparatorCategory.LOCATION_IGNORE_LIST
+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)
@@ -60,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)