RUBY-281 make BSON::OrderedHash#inspect more precise.

This commit is contained in:
Kyle Banker 2011-08-05 17:43:39 -04:00
parent 28f0f7af3e
commit eca6653bc2
2 changed files with 4 additions and 3 deletions

View File

@ -119,9 +119,9 @@ module BSON
end end
def inspect def inspect
str = '{' str = "#<BSON::OrderedHash:0x#{self.object_id.to_s(16)} {"
str << (@ordered_keys || []).collect { |k| "\"#{k}\"=>#{self.[](k).inspect}" }.join(", ") str << (@ordered_keys || []).collect { |k| "\"#{k}\"=>#{self.[](k).inspect}" }.join(", ")
str << '}' str << '}>'
end end
def delete(key, &block) def delete(key, &block)

View File

@ -38,6 +38,7 @@ class OrderedHashTest < Test::Unit::TestCase
same_doc = BSON::OrderedHash.new same_doc = BSON::OrderedHash.new
same_doc['_id'] = 'ab12' same_doc['_id'] = 'ab12'
same_doc['name'] = 'test' same_doc['name'] = 'test'
list << doc list << doc
list << same_doc list << same_doc
@ -191,7 +192,7 @@ class OrderedHashTest < Test::Unit::TestCase
end end
def test_inspect_retains_order def test_inspect_retains_order
assert_equal '{"c"=>1, "a"=>2, "z"=>3}', @oh.inspect assert_equal "#<BSON::OrderedHash:0x#{@oh.object_id.to_s(16)} {\"c\"=>1, \"a\"=>2, \"z\"=>3}>", @oh.inspect
end end
def test_clear def test_clear