Implement BSON::ByteBuffer#==
This commit is contained in:
parent
08daf9c5f9
commit
6b4ca2461f
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue