Implement BSON::ByteBuffer#==

This commit is contained in:
Hongli Lai (Phusion) 2011-03-24 00:49:21 +01:00 committed by Kyle Banker
parent 08daf9c5f9
commit 6b4ca2461f
2 changed files with 15 additions and 0 deletions

View File

@ -231,6 +231,10 @@ module BSON
def more? def more?
@cursor < @str.size @cursor < @str.size
end end
def ==(other)
other.respond_to?(:to_s) && @str == other.to_s
end
def to_a def to_a
@str.unpack("C*") @str.unpack("C*")

View File

@ -186,5 +186,16 @@ class ByteBufferTest < Test::Unit::TestCase
@buf.get_int @buf.get_int
assert !@buf.more? assert !@buf.more?
end end
def test_equality
@buf = ByteBuffer.new("foo")
assert_equal @buf, @buf
assert_equal ByteBuffer.new(""), ByteBuffer.new("")
assert_equal ByteBuffer.new("123"), ByteBuffer.new("123")
assert_not_equal ByteBuffer.new("123"), ByteBuffer.new("1234")
assert_equal @buf, "foo"
assert_not_equal @buf, 123
assert_not_equal @buf, nil
end
end end