Sha256: 060a629c4d23faa9cb78384962111e5b03e53d80b25cebd6fb3e5470a0badda3

Contents?: true

Size: 993 Bytes

Versions: 93

Compression:

Stored size: 993 Bytes

Contents

require 'epitools'

describe Rash do

  attr_accessor :r
  
  before :each do
    @r = Rash.new(
      /hello/ => "hello",
      /world/ => "world",
      "other" => "whee",
      true    => false,
      1       => "awesome",
      1..1000 => "rangey",
      #/.+/ => "EVERYTHING"
    )
  end
  
  it "string lookups" do
    r["other"].should == "whee"
    r["well hello there"].should == "hello"
    r["the world is round"].should == "world"
    r.all("hello world").sort.should == ["hello", "world"]
  end

  it "regex lookups" do
    r[/other/].should == "whee"
  end

  it "other objects" do  
    r[true].should == false
    r[1].should == "awesome"
  end
  
  it "does ranges" do
    @r[250].should == "rangey"
    @r[999].should == "rangey"
    @r[1000].should == "rangey"
    @r[1001].should == nil
  end
  
  it "calls procs on matches when they're values" do
    r = Rash.new( /(ello)/ => proc { |m| m[1] } )
    r["hello"].should == "ello"
    r["ffffff"].should == nil
  end
  
end

Version data entries

93 entries across 93 versions & 1 rubygems

Version Path
epitools-0.5.103 spec/rash_spec.rb
epitools-0.5.100 spec/rash_spec.rb
epitools-0.5.99 spec/rash_spec.rb
epitools-0.5.98 spec/rash_spec.rb
epitools-0.5.97 spec/rash_spec.rb
epitools-0.5.96 spec/rash_spec.rb
epitools-0.5.95 spec/rash_spec.rb
epitools-0.5.94 spec/rash_spec.rb
epitools-0.5.93 spec/rash_spec.rb
epitools-0.5.92 spec/rash_spec.rb
epitools-0.5.91 spec/rash_spec.rb
epitools-0.5.90 spec/rash_spec.rb
epitools-0.5.89 spec/rash_spec.rb
epitools-0.5.88 spec/rash_spec.rb
epitools-0.5.87 spec/rash_spec.rb
epitools-0.5.86 spec/rash_spec.rb
epitools-0.5.85 spec/rash_spec.rb
epitools-0.5.84 spec/rash_spec.rb
epitools-0.5.83 spec/rash_spec.rb
epitools-0.5.82 spec/rash_spec.rb