Skip to content
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

==: Fix to compare with address prefix #69

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/ipaddr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ def ==(other)
rescue
false
else
@family == other.family && @addr == other.to_i
@family == other.family && @addr == other.to_i && prefix == other.prefix
end

# Returns a new ipaddr built by masking IP address with the given
Expand Down
49 changes: 45 additions & 4 deletions test/test_ipaddr.rb
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,53 @@ def test_carrot
end

def test_equal
assert_equal(true, @a == IPAddr.new("3FFE:505:2::"))
assert_equal(true, @a == IPAddr.new("3ffe:0505:0002::"))
assert_equal(true, @a == IPAddr.new("3ffe:0505:0002:0:0:0:0:0"))
a = IPAddr.new("192.168.2.0")
assert_equal(true, a == IPAddr.new("192.168.2.0"))
assert_equal(false, a == IPAddr.new("192.168.2.0/24"))
assert_equal(false, a == IPAddr.new("192.168.3.0"))
assert_equal(false, a == IPAddr.new("192.168.3.0/24"))
assert_equal(false, a != IPAddr.new("192.168.2.0"))
assert_equal(true, a != IPAddr.new("192.168.2.0/24"))
assert_equal(true, a != IPAddr.new("192.168.3.0"))
assert_equal(true, a != IPAddr.new("192.168.3.0/24"))

a = IPAddr.new("192.168.2.0/24")
assert_equal(false, a == IPAddr.new("192.168.2.0"))
assert_equal(true, a == IPAddr.new("192.168.2.0/24"))
assert_equal(false, a == IPAddr.new("192.168.2.0/25"))
assert_equal(false, a == IPAddr.new("192.168.3.0"))
assert_equal(false, a == IPAddr.new("192.168.3.0/24"))
assert_equal(true, a != IPAddr.new("192.168.2.0"))
assert_equal(false, a != IPAddr.new("192.168.2.0/24"))
assert_equal(true, a != IPAddr.new("192.168.2.0/25"))
assert_equal(true, a != IPAddr.new("192.168.3.0"))
assert_equal(true, a != IPAddr.new("192.168.3.0/24"))

a = IPAddr.new("3ffe:505:2::")
assert_equal(true, a == IPAddr.new("3FFE:505:2::"))
assert_equal(false, a == IPAddr.new("3FFE:505:2::/48"))
assert_equal(true, a == IPAddr.new("3ffe:0505:0002::"))
assert_equal(true, a == IPAddr.new("3ffe:0505:0002:0:0:0:0:0"))
assert_equal(false, a == IPAddr.new("3ffe:505:3::"))
assert_equal(false, a == IPAddr.new("3ffe:505:3::/48"))
assert_equal(false, a != IPAddr.new("3ffe:505:2::"))
assert_equal(true, a != IPAddr.new("3ffe:505:2::/48"))
assert_equal(true, a != IPAddr.new("3ffe:505:3::"))
assert_equal(true, a != IPAddr.new("3ffe:505:3::/48"))

assert_equal(false, @a == IPAddr.new("3FFE:505:2::"))
assert_equal(true, @a == IPAddr.new("3FFE:505:2::/48"))
assert_equal(false, @a == IPAddr.new("3FFE:505:2::/49"))
assert_equal(true, @a == IPAddr.new("3ffe:0505:0002::/48"))
assert_equal(true, @a == IPAddr.new("3ffe:0505:0002:0:0:0:0:0/48"))
assert_equal(false, @a == IPAddr.new("3ffe:505:3::"))
assert_equal(false, @a == IPAddr.new("3ffe:505:3::/48"))
assert_equal(true, @a != IPAddr.new("3ffe:505:2::"))
assert_equal(false, @a != IPAddr.new("3ffe:505:2::/48"))
assert_equal(true, @a != IPAddr.new("3ffe:505:2::/49"))
assert_equal(true, @a != IPAddr.new("3ffe:505:3::"))
assert_equal(false, @a != IPAddr.new("3ffe:505:2::"))
assert_equal(true, @a != IPAddr.new("3ffe:505:3::/48"))

assert_equal(false, @a == @inconvertible_range)
assert_equal(false, @a == @inconvertible_string)
end
Expand Down