Sha256: 25058c3ae84210fb05622b9149b860d6d5e291abe17298a0f1a42ff79f1f4532

Contents?: true

Size: 1.16 KB

Versions: 5

Compression:

Stored size: 1.16 KB

Contents

# coding: utf-8

require 'test/unit/helper'

include ThinReports::TestHelpers

describe 'OrderedHash#[]=' do
  before do
    skip_if_ruby19
    @ohash = ThinReports::Core::OrderedHash.new
  end
  
  it 'should be given keys in stored in the keys array' do
    @ohash[:foo]  = 'foo'
    @ohash[:hoge] = 'hoge'
    @ohash.instance_variable_get(:@keys).must_equal [:foo, :hoge]
  end
  
  it 'should properly set the given value' do
    @ohash[:foo] = 'foo'
    @ohash[:foo].must_equal 'foo'
  end
  
  it 'should not exist a duplicate key in store of key' do
    @ohash[:foo] = 'foo1'
    @ohash[:foo] = 'foo2'
    @ohash.instance_variable_get(:@keys).uniq.size.must_equal 1
  end
end

describe 'OrderedHash#each_key' do
  it 'should get the key in the order registerd' do
    skip_if_ruby19
    
    ohash = ThinReports::Core::OrderedHash.new    
    (keys = [:key3, :key1, :key2]).each {|key| ohash[key] = key.to_s }
    
    i = 0
    ohash.each_key do |key|
      key.must_equal keys[i]; i += 1
    end
  end
end

describe 'OrderedHash on Ruby 1.9' do
  it 'should same Hash class on Ruby 1.9' do
    skip_if_ruby18
    
    ThinReports::Core::OrderedHash.must_be_same_as ::Hash
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
thinreports-0.7.7 test/unit/core/ordered_hash_spec.rb
thinreports-0.7.6 test/unit/core/ordered_hash_spec.rb
thinreports-0.7.5 test/unit/core/ordered_hash_spec.rb
thinreports-0.7.0 test/unit/core/ordered_hash_spec.rb
thinreports-0.6.0.pre3 test/unit/core/ordered_hash_spec.rb