Files
news.gitea.happylizard.me/bin/gems/hashery-2.1.2/test/case_casting_hash.rb
T
pizza2d1 4cee170d66
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 9s
Add bin and edit workflow
2026-09-16 13:11:16 -06:00

72 lines
1.3 KiB
Ruby

require 'helper'
test_case CastingHash do
class_method :[] do
test do
h = CastingHash[:a=>1, :b=>2]
end
end
class_method :new do
test do
h = CastingHash.new
end
test 'with default' do
h = CastingHash.new(0)
h['a'].assert == 0
end
test 'with casting procedure' do
h = CastingHash.new{ |k,v| [k.to_sym, v] }
h['a'] = 1
h.assert == {:a=>1}
end
test 'with default and casting procedure' do
h = CastingHash.new(0){ |k,v| [k.to_sym, v] }
h['a'].assert == 0
h['b'] = 2
h.assert == {:b=>2}
end
end
method :recast! do
test do
h = CastingHash[:a=>1, :b=>2]
h.cast_proc{ |k,v| [k.to_s, v] }
h.recast!
h.assert == {'a'=>1, 'b'=>2}
end
end
method :cast_proc= do
test do
h = CastingHash[:a=>1, :b=>2]
h.cast_proc = Proc.new{ |k,v| [k.to_s, v] }
h.recast!
h.assert == {'a'=>1, 'b'=>2}
end
end
method :to_hash do
test do
h = CastingHash[:a=>1, :b=>2]
h.to_hash
::Hash.assert === h
h.assert == {:a=>1, :b=>2}
end
end
method :to_h do
test do
h = CastingHash[:a=>1, :b=>2]
h.to_h
::Hash.assert === h
h.assert == {:a=>1, :b=>2}
end
end
end