Sha256: b1e05c85dd40af0455dd773e821b88eebcc7c4acf4588c7f38fdd7bedcc8a021

Contents?: true

Size: 1.36 KB

Versions: 52

Compression:

Stored size: 1.36 KB

Contents

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

describe "Regexp.union" do
  it "returns /(?!)/ when passed no arguments" do
    Regexp.union.should == /(?!)/
  end

  it "returns a regular expression that will match passed arguments" do
    Regexp.union("penzance").should == /penzance/
    Regexp.union("skiing", "sledding").should == /skiing|sledding/
    Regexp.union(/dogs/, /cats/i).should == /(?-mix:dogs)|(?i-mx:cats)/
  end

  it "quotes any string arguments" do
    Regexp.union("n", ".").should == /n|\./
  end

  ruby_version_is '' ... '1.9' do
    it "propagates the kcode setting to the output Regexp" do
      Regexp.union(/./u, "meow").kcode.should == "utf8"
    end
  end

  it "raises ArgumentError if the kcodes conflict" do
    lambda {
      Regexp.union(/./u, /./e)
    }.should raise_error(ArgumentError)
  end

  it "uses to_str to convert arguments (if not Regexp)" do
    obj = mock('pattern')
    obj.should_receive(:to_str).and_return('foo')
    Regexp.union(obj, "bar").should == /foo|bar/
  end

  ruby_version_is '1.8.7' do
    it "accepts a single array of patterns as arguments" do
      Regexp.union(["skiing", "sledding"]).should == /skiing|sledding/
      Regexp.union([/dogs/, /cats/i]).should == /(?-mix:dogs)|(?i-mx:cats)/
      lambda{Regexp.union(["skiing", "sledding"], [/dogs/, /cats/i])}.should raise_error(TypeError)
    end
  end
end

Version data entries

52 entries across 52 versions & 2 rubygems

Version Path
rhodes-7.6.0 spec/framework_spec/app/spec/core/regexp/union_spec.rb
rhodes-7.5.1 spec/framework_spec/app/spec/core/regexp/union_spec.rb
rhodes-7.4.1 spec/framework_spec/app/spec/core/regexp/union_spec.rb
rhodes-7.1.17 spec/framework_spec/app/spec/core/regexp/union_spec.rb
rhodes-6.2.0 spec/framework_spec/app/spec/core/regexp/union_spec.rb
rhodes-6.0.11 spec/framework_spec/app/spec/core/regexp/union_spec.rb
rhodes-5.5.18 spec/framework_spec/app/spec/core/regexp/union_spec.rb
rhodes-5.5.17 spec/framework_spec/app/spec/core/regexp/union_spec.rb
rhodes-5.5.15 spec/framework_spec/app/spec/core/regexp/union_spec.rb
rhodes-5.5.0.22 spec/framework_spec/app/spec/core/regexp/union_spec.rb
rhodes-5.5.2 spec/framework_spec/app/spec/core/regexp/union_spec.rb
rhodes-5.5.0.7 spec/framework_spec/app/spec/core/regexp/union_spec.rb
rhodes-5.5.0.3 spec/framework_spec/app/spec/core/regexp/union_spec.rb
rhodes-5.5.0 spec/framework_spec/app/spec/core/regexp/union_spec.rb
tauplatform-1.0.3 spec/framework_spec/app/spec/core/regexp/union_spec.rb
tauplatform-1.0.2 spec/framework_spec/app/spec/core/regexp/union_spec.rb
tauplatform-1.0.1 spec/framework_spec/app/spec/core/regexp/union_spec.rb
rhodes-3.5.1.12 spec/framework_spec/app/spec/core/regexp/union_spec.rb
rhodes-3.3.5 spec/framework_spec/app/spec/core/regexp/union_spec.rb
rhodes-3.4.2 spec/framework_spec/app/spec/core/regexp/union_spec.rb