Uploaded image for project: 'Groovy'
  1. Groovy
  2. GROOVY-8026

Matcher indexed via IntRange with startIdx..-1 does not return "intermediate" range matches

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Closed
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.4.7
    • Fix Version/s: 2.4.9
    • Component/s: groovy-jdk
    • Labels:
      None
    • Environment:
      Zulu OpenJDK 1.8.0_102-b14
      Windows 7 Pro

      Description

      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:

      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]
      

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                paulk Paul King
                Reporter:
                brianeray Brian Ray
              • Votes:
                0 Vote for this issue
                Watchers:
                2 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved: