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
The following commit(s) were added to refs/heads/GROOVY-8258 by this push:
new 7f4b0dd GROOVY-8258: add more test cases
7f4b0dd is described below
commit 7f4b0dd9db58e4e624ca56a6de3fe2afc0faeb57
Author: Daniel Sun <[email protected]>
AuthorDate: Thu Oct 8 01:43:16 2020 +0800
GROOVY-8258: add more test cases
---
.../linq/provider/collection/GinqAstWalker.groovy | 14 +++--
.../groovy/org/apache/groovy/linq/GinqTest.groovy | 59 ++++++++++++++++++++++
2 files changed, 68 insertions(+), 5 deletions(-)
diff --git
a/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/provider/collection/GinqAstWalker.groovy
b/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/provider/collection/GinqAstWalker.groovy
index 3361172..63328c3 100644
---
a/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/provider/collection/GinqAstWalker.groovy
+++
b/subprojects/groovy-linq/src/main/groovy/org/apache/groovy/linq/provider/collection/GinqAstWalker.groovy
@@ -136,12 +136,16 @@ class GinqAstWalker implements GinqVisitor<Object>,
SyntaxErrorReportable {
)
}
- OnExpression onExpression = filterExpressionList.isEmpty() ? null :
(OnExpression) filterExpressionList.get(0)
-
- WhereExpression whereExpression = null
- if (filterExpressionListSize > 1) {
- whereExpression = (WhereExpression) filterExpressionList.get(1)
+ OnExpression onExpression
+ int whereExpressionPos
+ if (joinExpression.isCrossJoin()) {
+ onExpression = null
+ whereExpressionPos = 0
+ } else {
+ onExpression = (OnExpression) filterExpressionList.get(0)
+ whereExpressionPos = 1
}
+ WhereExpression whereExpression = filterExpressionList.size() <
(whereExpressionPos + 1) ? null : (WhereExpression)
filterExpressionList.get(whereExpressionPos)
MethodCallExpression joinMethodCallExpression =
constructJoinMethodCallExpression(receiver, receiverAliasExpr, joinExpression,
onExpression, whereExpression)
diff --git
a/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/GinqTest.groovy
b/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/GinqTest.groovy
index d10c345..a4310a3 100644
---
a/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/GinqTest.groovy
+++
b/subprojects/groovy-linq/src/test/groovy/org/apache/groovy/linq/GinqTest.groovy
@@ -769,6 +769,21 @@ class GinqTest {
}
@Test
+ void "testGinq - from leftJoin where select - 1"() {
+ assertScript '''
+ def nums1 = [1, 2, 3]
+ def nums2 = [2, 3, 4, null, null]
+ assert [[2, 2], [3, 3]] == GINQ {
+ from n1 in nums1
+ leftJoin n2 in nums2
+ on n1 == n2
+ where n2 != null
+ select n1, n2
+ }.toList()
+ '''
+ }
+
+ @Test
void "testGinq - from rightJoin select - 1"() {
assertScript '''
def nums1 = [1, 2, 3]
@@ -909,6 +924,21 @@ class GinqTest {
}
@Test
+ void "testGinq - from rightJoin where select - 1"() {
+ assertScript '''
+ def nums2 = [1, 2, 3]
+ def nums1 = [2, 3, 4, null, null]
+ assert [[2, 2], [3, 3]] == GINQ {
+ from n1 in nums1
+ rightJoin n2 in nums2
+ on n1 == n2
+ where n1 != null
+ select n1, n2
+ }.toList()
+ '''
+ }
+
+ @Test
void "testGinq - from fullJoin select - 1"() {
assertScript '''
def nums1 = [1, 2, 3]
@@ -923,6 +953,21 @@ class GinqTest {
}
@Test
+ void "testGinq - from fullJoin where select - 1"() {
+ assertScript '''
+ def nums1 = [1, 2, 3]
+ def nums2 = [2, 3, 4]
+ assert [[2, 2], [3, 3]] == GINQ {
+ from n1 in nums1
+ fullJoin n2 in nums2
+ on n1 == n2
+ where n1 != null && n2 != null
+ select n1, n2
+ }.toList()
+ '''
+ }
+
+ @Test
void "testGinq - from crossJoin select - 1"() {
assertScript '''
def nums1 = [1, 2, 3]
@@ -934,4 +979,18 @@ class GinqTest {
}.toList()
'''
}
+
+ @Test
+ void "testGinq - from crossJoin where select - 1"() {
+ assertScript '''
+ def nums1 = [1, 2, 3]
+ def nums2 = [3, 4, 5]
+ assert [[3, 3], [3, 5]] == GINQ {
+ from n1 in nums1
+ crossJoin n2 in nums2
+ where n1 > 2 && n2 != 4
+ select n1, n2
+ }.toList()
+ '''
+ }
}