groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [groovy] 05/06: Add one more test for lambda
Date Wed, 11 Dec 2019 10:44:40 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 22dd2bf4683d7a6e4ea72e0b3f605b5e341756fd
Author: Daniel Sun <sunlan@apache.org>
AuthorDate: Wed Dec 11 15:21:10 2019 +0800

    Add one more test for lambda
    
    (cherry picked from commit 51b3289dc7373b7bdf35d3c9e7fcbf0c990ca503)
---
 src/test/groovy/transform/stc/LambdaTest.groovy | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

diff --git a/src/test/groovy/transform/stc/LambdaTest.groovy b/src/test/groovy/transform/stc/LambdaTest.groovy
index 3cdb6a1..7d02748 100644
--- a/src/test/groovy/transform/stc/LambdaTest.groovy
+++ b/src/test/groovy/transform/stc/LambdaTest.groovy
@@ -929,6 +929,26 @@ class LambdaTest extends GroovyTestCase {
         '''
     }
 
+    void testNestedLambdaAccessingInstanceFields() {
+        assertScript '''
+            @groovy.transform.CompileStatic
+            class Test1 {
+                private List<String> strList = ['a', 'e', 'f']
+                private Map<String, List<String>> strListHolder = ['strList':
strList]
+                private String b = 'b'
+                def p() {
+                    ['abc', 'def', 'ghi'].stream().filter(e -> strList.stream().anyMatch(c
-> e.contains(c + b))).toList()
+                }
+                def p2() {
+                    ['abc', 'def', 'ghi'].stream().filter(e -> strListHolder.strList.stream().anyMatch(c
-> e.contains(c + b))).toList()
+                }
+            }
+            
+            assert ['abc'] == new Test1().p()
+            assert ['abc'] == new Test1().p2()
+        '''
+    }
+
     void testSerialize() {
         assertScript '''
         import java.util.function.Function


Mime
View raw message