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

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

commit 9ff78df0042931e312aeb431f07056b0141c8250
Author: Daniel Sun <[email protected]>
AuthorDate: Mon Oct 5 04:25:12 2020 +0800

    GROOVY-8258: Add 2 test cases
---
 .../apache/groovy/linq/LinqGroovyMethods.groovy    | 12 ++++++++++--
 .../groovy/org/apache/groovy/linq/LinqTest.groovy  | 22 ++++++++++++++++++++++
 2 files changed, 32 insertions(+), 2 deletions(-)

diff --git 
a/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/LinqGroovyMethods.groovy
 
b/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/LinqGroovyMethods.groovy
index ff368fb..71c3fe5 100644
--- 
a/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/LinqGroovyMethods.groovy
+++ 
b/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/LinqGroovyMethods.groovy
@@ -83,13 +83,21 @@ class LinqGroovyMethods {
         Map.Entry<VariableExpression, Expression> fromEntry = 
linqContext.fromMap.entrySet().toList().get(0)
         VariableExpression aliasVariable = fromEntry.key
 
+        Expression selectMethodReceiver = null
+
         MethodCallExpression from = macro {
             org.apache.groovy.linq.provider.QueryableCollection
                     .from($v { fromEntry.value })
         }
 
-        MethodCallExpression where = callXWithClosure(from, "where", 
aliasVariable.name, linqContext.whereList[0])
-        MethodCallExpression select = callXWithClosure(where, "select", 
aliasVariable.name, linqContext.selectList[0])
+        selectMethodReceiver = from
+
+        if (linqContext.whereList.size() > 0) {
+            MethodCallExpression where = callXWithClosure(from, "where", 
aliasVariable.name, linqContext.whereList[0])
+            selectMethodReceiver = where
+        }
+
+        MethodCallExpression select = callXWithClosure(selectMethodReceiver, 
"select", aliasVariable.name, linqContext.selectList[0])
 
         return select
     }
diff --git 
a/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/LinqTest.groovy
 
b/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/LinqTest.groovy
index a19d39e..b2b0887 100644
--- 
a/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/LinqTest.groovy
+++ 
b/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/LinqTest.groovy
@@ -28,6 +28,28 @@ import static groovy.test.GroovyAssert.assertScript
 @CompileStatic
 class LinqTest {
     @Test
+    void "testLinqMacroMethod - from select - 1"() {
+        assertScript '''
+            def numbers = [0, 1, 2]
+            assert [0, 1, 2] == LINQ {
+                from n of numbers
+                select n
+            }.toList()
+        '''
+    }
+
+    @Test
+    void "testLinqMacroMethod - from select - 2"() {
+        assertScript '''
+            def numbers = [0, 1, 2]
+            assert [0, 2, 4] == LINQ {
+                from n of numbers
+                select n * 2
+            }.toList()
+        '''
+    }
+
+    @Test
     void "testLinqMacroMethod - from where select"() {
         assertScript '''
             def numbers = [0, 1, 2, 3, 4, 5]

Reply via email to