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.81 spec/rash_spec.rb
epitools-0.5.79 spec/rash_spec.rb
epitools-0.5.78 spec/rash_spec.rb
epitools-0.5.77 spec/rash_spec.rb
epitools-0.5.75 spec/rash_spec.rb
epitools-0.5.74 spec/rash_spec.rb
epitools-0.5.73 spec/rash_spec.rb
epitools-0.5.72 spec/rash_spec.rb
epitools-0.5.71 spec/rash_spec.rb
epitools-0.5.70 spec/rash_spec.rb
epitools-0.5.69 spec/rash_spec.rb
epitools-0.5.68 spec/rash_spec.rb
epitools-0.5.67 spec/rash_spec.rb
epitools-0.5.66 spec/rash_spec.rb
epitools-0.5.65 spec/rash_spec.rb
epitools-0.5.64 spec/rash_spec.rb
epitools-0.5.63 spec/rash_spec.rb
epitools-0.5.61 spec/rash_spec.rb
epitools-0.5.60 spec/rash_spec.rb
epitools-0.5.59 spec/rash_spec.rb