Repository: groovy
Updated Branches:
  refs/heads/parrot a9c704665 -> d21ddc7ab


GROOVY-8026: Matcher indexed via IntRange with startIdx..-1 does not return 
"intermediate" range matches (closes #483)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/598b93e0
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/598b93e0
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/598b93e0

Branch: refs/heads/parrot
Commit: 598b93e04767c0511860758531bff56975e49e53
Parents: 84462bb
Author: paulk <pa...@asert.com.au>
Authored: Fri Jan 27 16:58:50 2017 +1000
Committer: paulk <pa...@asert.com.au>
Committed: Mon Jan 30 22:56:39 2017 +1000

----------------------------------------------------------------------
 .../groovy/runtime/StringGroovyMethods.java     |  5 +++
 src/test/groovy/bugs/Groovy8026Bug.groovy       | 35 ++++++++++++++++++++
 2 files changed, 40 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/598b93e0/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
----------------------------------------------------------------------
diff --git a/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java 
b/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
index 2d41ac3..2fded6f 100644
--- a/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
+++ b/src/main/org/codehaus/groovy/runtime/StringGroovyMethods.java
@@ -1348,6 +1348,11 @@ public class StringGroovyMethods extends 
DefaultGroovyMethodsSupport {
      */
     public static List getAt(Matcher self, Collection indices) {
         List result = new ArrayList();
+        if (indices instanceof IntRange) {
+            int size = (int) size(self);
+            RangeInfo info = subListBorders(size, (Range) indices);
+            indices = new IntRange(((IntRange)indices).getInclusive(), 
info.from, info.to - 1);
+        }
         for (Object value : indices) {
             if (value instanceof Range) {
                 result.addAll(getAt(self, (Range) value));

http://git-wip-us.apache.org/repos/asf/groovy/blob/598b93e0/src/test/groovy/bugs/Groovy8026Bug.groovy
----------------------------------------------------------------------
diff --git a/src/test/groovy/bugs/Groovy8026Bug.groovy 
b/src/test/groovy/bugs/Groovy8026Bug.groovy
new file mode 100644
index 0000000..8483ee0
--- /dev/null
+++ b/src/test/groovy/bugs/Groovy8026Bug.groovy
@@ -0,0 +1,35 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ *
+ *    http://www.apache.org/licenses/LICENSE-2.0
+ *
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package groovy.bugs
+
+class Groovy8026Bug extends GroovyTestCase {
+    void testJavaBeanPropertiesAvailableInInnerClasses() {
+        assertScript '''
+            def mm = '1 2 3 4 5 6 7 8 9' =~ /\\d/
+            assert mm.collect { it }.toString() == '[1, 2, 3, 4, 5, 6, 7, 8, 
9]'
+            assert mm[ 0..8 ].toString() == '[1, 2, 3, 4, 5, 6, 7, 8, 9]'
+            assert mm[ 0..mm.size()-1 ].toString() == '[1, 2, 3, 4, 5, 6, 7, 
8, 9]'
+            assert mm[ 0..<mm.size() ].toString() == '[1, 2, 3, 4, 5, 6, 7, 8, 
9]'
+            assert mm[-1] == '9'
+            assert mm[ 0..-1 ].toString() == '[1, 2, 3, 4, 5, 6, 7, 8, 9]'
+            assert mm[ (0..-1).toList() ].toString() == '[1, 9]'
+            assert mm[ (0..-1).iterator().toList() ].toString() == '[1, 9]'
+        '''
+    }
+}

Reply via email to