New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

lib/ipaddr.rb : Return false instead of throwing an exception in == test #1435

Closed
wants to merge 2 commits into
base: trunk
from
Jump to file or symbol
Failed to load files and symbols.
+19 −2
Diff settings

Always

Just for now

View
@@ -148,7 +148,11 @@ def ~
# Returns true if two ipaddrs are equal.
def ==(other)
other = coerce_other(other)
begin
other = coerce_other(other)
rescue
return false
end
return @family == other.family && @addr == other.to_i
end
@@ -334,7 +338,11 @@ def succ
# Compares the ipaddr with another.
def <=>(other)
other = coerce_other(other)
begin
other = coerce_other(other)
rescue
return nil
end
return nil if other.family != @family
View
@@ -169,6 +169,8 @@ def setup
@a = IPAddr.new("3ffe:505:2::/48")
@b = IPAddr.new("0:0:0:1::")
@c = IPAddr.new(IN6MASK32)
@inconvertible_range = 1..5
@inconvertible_string = "sometext"
end
alias set_up setup
@@ -220,6 +222,13 @@ def test_equal
assert_equal(false, @a == IPAddr.new("3ffe:505:3::"))
assert_equal(true, @a != IPAddr.new("3ffe:505:3::"))
assert_equal(false, @a != IPAddr.new("3ffe:505:2::"))
assert_equal(false, @a == @inconvertible_range)
assert_equal(false, @a == @inconvertible_string)
end
def test_compare
assert_equal(nil, @a <=> @inconvertible_range)
assert_equal(nil, @a <=> @inconvertible_string)
end
def test_mask