RUBY-258 Bytebuffer#unpack takes arbitrary format string

This commit is contained in:
Kyle Banker 2011-04-01 13:36:28 -04:00
parent a19d5bc983
commit 3187761670
2 changed files with 11 additions and 4 deletions

View File

@ -236,12 +236,12 @@ module BSON
other.respond_to?(:to_s) && @str == other.to_s
end
def to_a
@str.unpack("C*")
def to_a(format="C*")
@str.unpack(format)
end
def unpack(args)
to_a
def unpack(format="C*")
to_a(format)
end
def to_s

View File

@ -21,6 +21,13 @@ class ByteBufferTest < Test::Unit::TestCase
assert_equal 1, @buf.get
end
def test_unpack
@buf.put_array([17, 2, 3, 4])
assert_equal [17, 2, 3, 4], @buf.to_a
assert_equal ["11020304"], @buf.unpack("H*")
assert_equal ["11020304"], @buf.to_a("H*")
end
def test_one_get_returns_array_length_one
@buf.put_array([1, 2, 3, 4])
@buf.rewind