Sha256: 98e0d34ff5d262d7fb6b9e35a3830386b3a221786e25f9e8a2601cb4a59c13ee

Contents?: true

Size: 1.43 KB

Versions: 52

Compression:

Stored size: 1.43 KB

Contents

require File.expand_path('../../../spec_helper', __FILE__)
require File.expand_path('../../fixtures/classes', __FILE__)

describe "Regexps with back-references" do
  it 'saves match data in the $~ pseudo-global variable' do
    "hello" =~ /l+/
    $~.to_a.should == ["ll"]
  end

  it 'saves captures in numbered $[1-9] variables' do
    "1234567890" =~ /(1)(2)(3)(4)(5)(6)(7)(8)(9)(0)/
    $~.to_a.should == ["1234567890", "1", "2", "3", "4", "5", "6", "7", "8", "9", "0"]
    $1.should == "1"
    $2.should == "2"
    $3.should == "3"
    $4.should == "4"
    $5.should == "5"
    $6.should == "6"
    $7.should == "7"
    $8.should == "8"
    $9.should == "9"
  end

  it 'will not clobber capture variables across threads' do
    cap1, cap2, cap3 = nil
    "foo" =~ /(o+)/
    cap1 = [$~.to_a, $1]
    Thread.new do
      cap2 = [$~.to_a, $1]
      "bar" =~ /(a)/
      cap3 = [$~.to_a, $1]
    end.join
    cap4 = [$~.to_a, $1]
    cap1.should == [["oo", "oo"], "oo"]
    cap2.should == [[], nil]
    cap3.should == [["a", "a"], "a"]
    cap4.should == [["oo", "oo"], "oo"]
  end

  it 'supports \<n> (backreference to previous group match)' do
    /(foo.)\1/.match("foo1foo1").to_a.should == ["foo1foo1", "foo1"]
    /(foo.)\1/.match("foo1foo2").should be_nil
  end

  not_compliant_on :ironruby do
    it 'resets nested \<n> backreference before match of outer subexpression' do
      /(a\1?){2}/.match("aaaa").to_a.should == ["aa", "a"]
    end
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
rhodes-3.2.2 spec/framework_spec/app/spec/language/regexp/back-references_spec.rb
rhodes-3.2.2.beta spec/framework_spec/app/spec/language/regexp/back-references_spec.rb
rhodes-3.2.1 spec/framework_spec/app/spec/language/regexp/back-references_spec.rb
rhodes-3.2.0 spec/framework_spec/app/spec/language/regexp/back-references_spec.rb
rhodes-3.2.0.beta.9 spec/framework_spec/app/spec/language/regexp/back-references_spec.rb
rhodes-3.2.0.beta.8 spec/framework_spec/app/spec/language/regexp/back-references_spec.rb
rhodes-3.2.0.beta.7 spec/framework_spec/app/spec/language/regexp/back-references_spec.rb
rhodes-3.2.0.beta.6 spec/framework_spec/app/spec/language/regexp/back-references_spec.rb
rhodes-3.2.0.beta.5 spec/framework_spec/app/spec/language/regexp/back-references_spec.rb
rhodes-3.2.0.beta.4 spec/framework_spec/app/spec/language/regexp/back-references_spec.rb
rhodes-3.2.0.beta.2 spec/framework_spec/app/spec/language/regexp/back-references_spec.rb
rhodes-3.2.0.beta.1 spec/framework_spec/app/spec/language/regexp/back-references_spec.rb