Sha256: 1f22f725d5dfc6e5c86d4aa9153f9f93ff199335b24f8090a20787ba610660e6

Contents?: true

Size: 982 Bytes

Versions: 27

Compression:

Stored size: 982 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

27 entries across 27 versions & 1 rubygems

Version Path
epitools-0.5.136 spec/rash_spec.rb
epitools-0.5.134 spec/rash_spec.rb
epitools-0.5.133 spec/rash_spec.rb
epitools-0.5.131 spec/rash_spec.rb
epitools-0.5.130 spec/rash_spec.rb
epitools-0.5.129 spec/rash_spec.rb
epitools-0.5.128 spec/rash_spec.rb
epitools-0.5.126 spec/rash_spec.rb
epitools-0.5.125 spec/rash_spec.rb
epitools-0.5.124 spec/rash_spec.rb
epitools-0.5.123 spec/rash_spec.rb
epitools-0.5.122 spec/rash_spec.rb
epitools-0.5.121 spec/rash_spec.rb
epitools-0.5.119 spec/rash_spec.rb
epitools-0.5.118 spec/rash_spec.rb
epitools-0.5.116 spec/rash_spec.rb
epitools-0.5.115 spec/rash_spec.rb
epitools-0.5.114 spec/rash_spec.rb
epitools-0.5.113 spec/rash_spec.rb
epitools-0.5.112 spec/rash_spec.rb