Permalink
Browse files

GROOVY-5865: DefaultGroovyMethods.getAt(List, Range) delegates now to…

… getAt(List, EmptyRange) in case of EmptyRange.

This fixes issue with inconsistent behavior of getAt(List, Collection) where element of collection is EmptyRange. For details please see the JIRA ticket.
  • Loading branch information...
michal-mally committed Jan 15, 2013
1 parent 174b583 commit c45d2bd2e60bfc0352c0923ddccc9e34b94c10f6
@@ -4856,6 +4856,10 @@ public static int size(Object[] self) {
* @since 1.0
*/
public static <T> List<T> getAt(List<T> self, Range range) {
if (range instanceof EmptyRange) {
return getAt(self, (EmptyRange) range);
}
RangeInfo info = subListBorders(self.size(), range);
List<T> answer = self.subList(info.from, info.to); // sublist is always exclusive, but Ranges are not
if (info.reverse) {
@@ -167,6 +167,13 @@ class SubscriptTest extends GroovyTestCase {
assert sub == [101, 103, 120, 121, 122, 123, 124, 125, 133]
}
// GROOVY-5865
void testListSubscriptWithListAndEmptyRange() {
def list = [0, 1, 2]
assert list[0, 1..<1] == [0]
}
void testStringWithSubscriptList() {
def text = "nice cheese gromit!"

0 comments on commit c45d2bd

Please sign in to comment.