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

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

View File

@ -187,4 +187,15 @@ class ByteBufferTest < Test::Unit::TestCase
assert !@buf.more?
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