groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject groovy git commit: Add more tests
Date Fri, 12 Jan 2018 14:47:07 GMT
Repository: groovy
Updated Branches:
  refs/heads/native-lambda 6aeaa1c5a -> 4172bd764


Add more tests


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/4172bd76
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/4172bd76
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/4172bd76

Branch: refs/heads/native-lambda
Commit: 4172bd76428ce2c71a95dbc683323fba7385bda8
Parents: 6aeaa1c
Author: sunlan <sunlan@apache.org>
Authored: Fri Jan 12 22:46:59 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Fri Jan 12 22:46:59 2018 +0800

----------------------------------------------------------------------
 .../asm/sc/StaticTypesLambdaWriter.java         |   4 -
 src/test/groovy/transform/stc/LambdaTest.groovy | 111 +++++++++++++++++--
 2 files changed, 100 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/4172bd76/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
index cdb627b..c847c33 100644
--- a/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
+++ b/src/main/java/org/codehaus/groovy/classgen/asm/sc/StaticTypesLambdaWriter.java
@@ -27,12 +27,10 @@ import org.codehaus.groovy.ast.Parameter;
 import org.codehaus.groovy.ast.expr.ClosureExpression;
 import org.codehaus.groovy.ast.expr.Expression;
 import org.codehaus.groovy.ast.expr.LambdaExpression;
-import org.codehaus.groovy.classgen.AsmClassGenerator;
 import org.codehaus.groovy.classgen.asm.BytecodeHelper;
 import org.codehaus.groovy.classgen.asm.LambdaWriter;
 import org.codehaus.groovy.classgen.asm.WriterController;
 import org.codehaus.groovy.classgen.asm.WriterControllerFactory;
-import org.objectweb.asm.ClassVisitor;
 import org.objectweb.asm.Handle;
 import org.objectweb.asm.MethodVisitor;
 import org.objectweb.asm.Opcodes;
@@ -45,9 +43,7 @@ import java.util.Map;
 import java.util.stream.Collectors;
 
 import static org.codehaus.groovy.classgen.asm.sc.StaticInvocationWriter.PARAMETER_TYPE;
-import static org.objectweb.asm.Opcodes.ACC_FINAL;
 import static org.objectweb.asm.Opcodes.ACC_PUBLIC;
-import static org.objectweb.asm.Opcodes.ACC_STATIC;
 
 /**
  * Writer responsible for generating lambda classes in statically compiled mode.

http://git-wip-us.apache.org/repos/asf/groovy/blob/4172bd76/src/test/groovy/transform/stc/LambdaTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/transform/stc/LambdaTest.groovy b/src/test/groovy/transform/stc/LambdaTest.groovy
index e7ae05f..db4aa36 100644
--- a/src/test/groovy/transform/stc/LambdaTest.groovy
+++ b/src/test/groovy/transform/stc/LambdaTest.groovy
@@ -20,7 +20,7 @@
 package groovy.transform.stc
 
 class LambdaTest extends GroovyTestCase {
-    void testMethodCall() {
+    void testFunction() {
         assertScript '''
         import groovy.transform.CompileStatic
         import java.util.stream.Collectors
@@ -29,22 +29,35 @@ class LambdaTest extends GroovyTestCase {
         @CompileStatic
         public class Test1 {
             public static void main(String[] args) {
-                p1();
+                p();
             }
         
-            public static void p1() {
+            public static void p() {
                 assert [2, 3, 4] == Stream.of(1, 2, 3).map(e -> e.plus 1).collect(Collectors.toList());
             }
         }
         '''
-
     }
 
-    void testMethodCall2() {
+    void testBinaryOperator() {
         if (true) return;
 
         // the test can pass only in dynamic mode now, it can not pass static type checking...
 
+        /* TODO
+TestScript0.groovy: 13: [Static type checking] - Cannot find matching method java.util.stream.Stream#reduce(int,
groovy.lang.Closure). Please check if the declared type is correct and if the method exists.
+ @ line 13, column 30.
+                   assert 13 == Stream.of(1, 2, 3).reduce(7, (r, e) -> r + e);
+                                ^
+
+TestScript0.groovy: 13: [Static type checking] - Cannot find matching method java.lang.Object#plus(java.lang.Object).
Please check if the declared type is correct and if the method exists.
+ @ line 13, column 69.
+   (1, 2, 3).reduce(7, (r, e) -> r + e);
+                                 ^
+
+2 errors
+         */
+
         assertScript '''
         import groovy.transform.CompileStatic
         import java.util.stream.Collectors
@@ -53,18 +66,17 @@ class LambdaTest extends GroovyTestCase {
         @CompileStatic
         public class Test1 {
             public static void main(String[] args) {
-                p2();
+                p();
             }
             
-            public static void p2() {
+            public static void p() {
                 assert 13 == Stream.of(1, 2, 3).reduce(7, (r, e) -> r + e);
             }
         }
         '''
-
     }
 
-    void testMethodCall3() {
+    void testConsumer() {
         assertScript '''
         import groovy.transform.CompileStatic
         import java.util.stream.Collectors
@@ -73,15 +85,92 @@ class LambdaTest extends GroovyTestCase {
         @CompileStatic
         public class Test1 {
             public static void main(String[] args) {
-                p3();
+                p();
             }
             
-            public static void p3() {
+            public static void p() {
                 Stream.of(1, 2, 3).forEach(e -> { System.out.println(e + 1); });
             }
             
         }
         '''
+    }
+
+    void testPredicate() {
+        assertScript '''
+        import groovy.transform.CompileStatic
+        import java.util.stream.Collectors
+        import java.util.stream.Stream
+        
+        @CompileStatic
+        public class Test1 {
+            public static void main(String[] args) {
+                p();
+            }
+            
+            public static void p() {
+                def list = ['ab', 'bc', 'de']
+                list.removeIf(e -> e.startsWith("a"))
+                assert ['bc', 'de'] == list
+            }
+        }
+        '''
+    }
+
+    void testUnaryOperator() {
+        if (true) return;
+
+        /* TODO
+TestScript0.groovy: 14: [Static type checking] - Cannot find matching method java.util.List#replaceAll(groovy.lang.Closure).
Please check if the declared type is correct and if the method exists.
+ @ line 14, column 17.
+                   list.replaceAll(e -> e + 10)
+                   ^
+
+TestScript0.groovy: 14: [Static type checking] - Cannot find matching method java.lang.Object#plus(int).
Please check if the declared type is correct and if the method exists.
+ @ line 14, column 38.
+                   list.replaceAll(e -> e + 10)
+                                        ^
+
+2 errors
+         */
+
+        assertScript '''
+        import groovy.transform.CompileStatic
+        import java.util.stream.Collectors
+        import java.util.stream.Stream
+        
+        @CompileStatic
+        public class Test1 {
+            public static void main(String[] args) {
+                p();
+            }
+            
+            public static void p() {
+                def list = [1, 2, 3]
+                list.replaceAll(e -> e + 10)
+                assert [11, 12, 13] == list
+            }
+        }
+        '''
+    }
 
+    void testBiConsumer() {
+        assertScript '''
+        import groovy.transform.CompileStatic
+        import java.util.stream.Collectors
+        import java.util.stream.Stream
+        
+        @CompileStatic
+        public class Test1 {
+            public static void main(String[] args) {
+                p();
+            }
+            
+            public static void p() {
+                def map = [a: 1, b: 2, c: 3]
+                map.forEach((k, v) -> System.out.println(k + ":" + v));
+            }
+        }
+        '''
     }
 }


Mime
View raw message