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 2022/06/26 16:19:38 UTC

[groovy] 02/02: Add 2 more test cases for lambda

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

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

commit 297c840802b79af22ea48695af906f064a034333
Author: Daniel Sun <su...@apache.org>
AuthorDate: Mon Jun 27 00:19:01 2022 +0800

    Add 2 more test cases for lambda
---
 src/test/groovy/transform/stc/LambdaTest.groovy | 32 +++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

diff --git a/src/test/groovy/transform/stc/LambdaTest.groovy b/src/test/groovy/transform/stc/LambdaTest.groovy
index a0165db6a7..fab0a303f4 100644
--- a/src/test/groovy/transform/stc/LambdaTest.groovy
+++ b/src/test/groovy/transform/stc/LambdaTest.groovy
@@ -309,6 +309,38 @@ final class LambdaTest {
         '''
     }
 
+    @Test
+    void testCollectors1() {
+        assertScript '''
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            
+            @CompileStatic
+            def test() {
+                Set<String> set = ['a', 'b', 'c'] as Set
+                assert [a: 'a', b: 'b', c: 'c'] == set.stream().collect(Collectors.toMap(e -> e, e -> e))
+            }
+            
+            test()
+        '''
+    }
+
+    @Test
+    void testCollectors2() {
+        assertScript '''
+            import groovy.transform.CompileStatic
+            import java.util.stream.Collectors
+            
+            @CompileStatic
+            def test() {
+                Set<String> set = ['a', 'b', 'c'] as Set
+                assert [a: 'a', b: 'b', c: 'c'] == set.stream().collect(Collectors.toMap(e -> e, e -> e, (o1, o2) -> o2))
+            }
+            
+            test()
+        '''
+    }
+
     @Test
     void testFunctionWithLocalVariables() {
         assertScript '''