You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@groovy.apache.org by pa...@apache.org on 2015/06/01 13:53:21 UTC
incubator-groovy git commit: GROOVY-6212: SpreadExpression BUG! when
slicing a List
Repository: incubator-groovy
Updated Branches:
refs/heads/master b211ea336 -> f0bf0c867
GROOVY-6212: SpreadExpression BUG! when slicing a List
Project: http://git-wip-us.apache.org/repos/asf/incubator-groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-groovy/commit/f0bf0c86
Tree: http://git-wip-us.apache.org/repos/asf/incubator-groovy/tree/f0bf0c86
Diff: http://git-wip-us.apache.org/repos/asf/incubator-groovy/diff/f0bf0c86
Branch: refs/heads/master
Commit: f0bf0c867ff8d3ff947d12f75b78f1e2807fd6db
Parents: b211ea3
Author: Paul King <pa...@asert.com.au>
Authored: Mon Jun 1 10:43:49 2015 +1000
Committer: Paul King <pa...@asert.com.au>
Committed: Mon Jun 1 21:52:51 2015 +1000
----------------------------------------------------------------------
.../groovy/antlr/AntlrParserPlugin.java | 6 ++++
.../operator/SpreadListOperatorTest.groovy | 29 ++++++++++++++++++--
2 files changed, 33 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/f0bf0c86/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java b/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java
index d225ee6..25e3843 100644
--- a/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java
+++ b/src/main/org/codehaus/groovy/antlr/AntlrParserPlugin.java
@@ -2299,6 +2299,12 @@ public class AntlrParserPlugin extends ASTHelper implements ParserPlugin, Groovy
AST rightNode = leftNode.getNextSibling();
Expression rightExpression = expression(rightNode);
+ // easier to massage here than in the grammar
+ if (rightExpression instanceof SpreadExpression) {
+ ListExpression wrapped = new ListExpression();
+ wrapped.addExpression(rightExpression);
+ rightExpression = wrapped;
+ }
BinaryExpression binaryExpression = new BinaryExpression(leftExpression, makeToken(Types.LEFT_SQUARE_BRACKET, bracket), rightExpression);
configureAST(binaryExpression, indexNode);
http://git-wip-us.apache.org/repos/asf/incubator-groovy/blob/f0bf0c86/src/test/groovy/operator/SpreadListOperatorTest.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/operator/SpreadListOperatorTest.groovy b/src/test/groovy/operator/SpreadListOperatorTest.groovy
index 9a8a3af..1693878 100644
--- a/src/test/groovy/operator/SpreadListOperatorTest.groovy
+++ b/src/test/groovy/operator/SpreadListOperatorTest.groovy
@@ -19,8 +19,6 @@
package groovy.operator
/**
- * @version $Revision: 4996 $
- *
* <code>[2, 3].toSpreadList() equals to *[2, 3]</code> <br><br>
*
* For an example, <pre>
@@ -68,6 +66,33 @@ class SpreadListOperatorTest extends GroovyTestCase {
assert sum(*x, *x) == "fooBar-fooBar-"
}
+ void testSliceWithSpread() {
+ def result = (1..5)[1..3]
+ assert result == [2, 3, 4]
+ result = (1..5)[*1..3]
+ assert result == [2, 3, 4]
+ result = (1..5)[1..3, 0]
+ assert result == [2, 3, 4, 1]
+ result = (1..5)[*1..3, 0]
+ assert result == [2, 3, 4, 1]
+ }
+
+ void testSettingViaSpreadWithinIndex() {
+ def orig = 'a'..'f'
+
+ def items = orig.toList()
+ items[1..2] = 'X'
+ assert items == ['a', 'X', 'd', 'e', 'f']
+
+ items = orig.toList()
+ items[*1..2] = 'X'
+ assert items == ['a', 'X', 'X', 'd', 'e', 'f']
+
+ items = orig.toList()
+ items[*1..2, 4] = 'X'
+ assert items == ['a', 'X', 'X', 'd', 'X', 'f']
+ }
+
def sum(a, b, c, d) {
return a + b + c + d
}