1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* lib/csv.rb: Optimize header hashes by freezing string keys.

[ruby-core:58510]



git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@43825 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
jeg2 2013-11-24 00:44:41 +00:00
parent 34176b023e
commit 895e9b0acd
4 changed files with 32 additions and 1 deletions

View file

@ -198,6 +198,25 @@ class TestCSV::Interface < TestCSV
end
end
def test_write_hash_with_string_keys
File.unlink(@path)
lines = [{a: 1, b: 2, c: 3}, {a: 4, b: 5, c: 6}]
CSV.open( @path, "wb", headers: true ) do |csv|
csv << lines.first.keys
lines.each { |line| csv << line }
end
CSV.open( @path, "rb", headers: true ) do |csv|
csv.each do |line|
csv.headers.each_with_index do |header, h|
keys = line.to_hash.keys
assert_instance_of(String, keys[h])
assert_same(header, keys[h])
end
end
end
end
def test_write_hash_with_headers_array
File.unlink(@path)