[
https://issues.apache.org/jira/browse/GROOVY-8026?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15764736#comment-15764736
]
Brian Ray commented on GROOVY-8026:
-----------------------------------
Interesting. Here are expanded tests, just to see how close the symptoms are to
that issue.
{code:java}
//compare to GROOVY-5744 (multiple assignment from an Iterator skips every
other element)
otherTxt = '1 2 3 4 5 6 7 8 9'
mm = otherTxt =~ /\d/
println mm.collect { it } // [1, 2, 3, 4, 5, 6, 7, 8, 9]
println mm[ 0..8 ] // [1, 2, 3, 4, 5, 6, 7, 8, 9]
println mm[ 0..mm.size()-1 ] // [1, 2, 3, 4, 5, 6, 7, 8, 9]
println mm[ 0..<mm.size() ] // [1, 2, 3, 4, 5, 6, 7, 8, 9]
println mm[-1] // 9
println mm[ 0..-1 ] // the current inconsistency: [1, 9]
println mm[ (0..-1).toList() ] // [1, 9]
println mm[ (0..-1).iterator().toList() ] // [1, 9]
//for comparison
aa = [ 1, 2, 3, 4, 5, 6, 7, 8, 9 ]
println aa.collect { it } // [1, 2, 3, 4, 5, 6, 7, 8, 9]
println aa[ 0..8 ] // [1, 2, 3, 4, 5, 6, 7, 8, 9]
println aa[ 0..aa.size()-1 ] // [1, 2, 3, 4, 5, 6, 7, 8, 9]
println aa[ 0..<aa.size() ] // [1, 2, 3, 4, 5, 6, 7, 8, 9]
println aa[-1] // 9
println aa[ 0..-1 ] // [1, 2, 3, 4, 5, 6, 7, 8, 9]
println aa[ (0..-1).toList() ] // [1, 9]
println aa[ (0..-1).iterator().toList() ] // [1, 9]
{code}
The only mismatch between {{List#getAt(Range)}} and {{Matcher#getAt(Range)}}
(actually
[{{Matcher#getAt(Collection)}}|http://docs.groovy-lang.org/latest/html/groovy-jdk/java/util/regex/Matcher.html#getAt(java.util.Collection)]?)
seems to be this one scenario. Mechanically it is as if the {{Range}} is first
evaluated to a {{List}} when indexing a {{Matcher}}.
In contrast {{List#getAt(Range)}} is clever. It appears to convert the
{{Range}} end to the implied positive index before evaluating it.
> Matcher indexed via IntRange with startIdx..-1 does not return "intermediate"
> range matches
> -------------------------------------------------------------------------------------------
>
> Key: GROOVY-8026
> URL: https://issues.apache.org/jira/browse/GROOVY-8026
> Project: Groovy
> Issue Type: Bug
> Components: groovy-jdk
> Affects Versions: 2.4.7
> Environment: Zulu OpenJDK 1.8.0_102-b14
> Windows 7 Pro
> Reporter: Brian Ray
> Priority: Minor
>
> Maybe this isn't a bug, and I realize that a {{Matcher}} is not exactly a
> {{List}} or any other {{Collection}}, but the inconsistency is a little
> mysterious. Here's a simple Groovysh script with several comparative indexes:
> {code:java}
> txt = 'abcd 1 efgh 2 ijkl 3 mnop'
> m = txt =~ /\d/
> println m.collect { it } // as expected: [1, 2, 3]
> println m[ 0..2 ] // as expected: [1, 2, 3]
> println m[ 0..m.size()-1 ] // as expected: [1, 2, 3]
> println m[ 0..<m.size() ] // as expected: [1, 2, 3]
> println m[ 0..-1 ] // bug?: [1, 3]
> //for comparison
> a = [ 1, 2, 3 ]
> println a.collect { it } // [1, 2, 3]
> println a[ 0..2 ] // [1, 2, 3]
> println a[ 0..a.size()-1 ] // [1, 2, 3]
> println a[ 0..<a.size() ] // [1, 2, 3]
> println a[ 0..-1 ] // [1, 2, 3]
> {code}
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)