From commits-return-5207-archive-asf-public=cust-asf.ponee.io@groovy.apache.org Fri Jan 12 15:47:09 2018 Return-Path: X-Original-To: archive-asf-public@eu.ponee.io Delivered-To: archive-asf-public@eu.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by mx-eu-01.ponee.io (Postfix) with ESMTP id C5B8E180621 for ; Fri, 12 Jan 2018 15:47:09 +0100 (CET) Received: by cust-asf.ponee.io (Postfix) id B5C7C160C30; Fri, 12 Jan 2018 14:47:09 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id D68F5160C33 for ; Fri, 12 Jan 2018 15:47:08 +0100 (CET) Received: (qmail 12900 invoked by uid 500); 12 Jan 2018 14:47:08 -0000 Mailing-List: contact commits-help@groovy.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@groovy.apache.org Delivered-To: mailing list commits@groovy.apache.org Received: (qmail 12887 invoked by uid 99); 12 Jan 2018 14:47:08 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 12 Jan 2018 14:47:08 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id DFD73DFCB6; Fri, 12 Jan 2018 14:47:07 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: sunlan@apache.org To: commits@groovy.apache.org Message-Id: <8954ec6bf925415889fc6ef4db33e40c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: groovy git commit: Add more tests Date: Fri, 12 Jan 2018 14:47:07 +0000 (UTC) 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 Authored: Fri Jan 12 22:46:59 2018 +0800 Committer: sunlan 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)); + } + } + ''' } }