summaryrefslogtreecommitdiff
path: root/test/test_ipaddr.rb
diff options
context:
space:
mode:
authorEspartaco Palma <esparta@gmail.com>2018-10-27 17:13:31 -0700
committerHiroshi SHIBATA <hsbt@ruby-lang.org>2021-10-07 17:46:00 +0900
commitb23fba91ae60c71649cb5e5f8b63c87e6a63020f (patch)
tree918d2e9fded7eb4ce12332c57f32c0cad30863ea /test/test_ipaddr.rb
parent323e7a6744a18a729d8011e237e64291cb6c02bd (diff)
downloadruby-b23fba91ae60c71649cb5e5f8b63c87e6a63020f.tar.gz
[ruby/ipaddr] Removing superfluos assingments & return
Also adding test for ntop https://github.com/ruby/ipaddr/commit/0ba16cca10
Diffstat (limited to 'test/test_ipaddr.rb')
-rw-r--r--test/test_ipaddr.rb17
1 files changed, 17 insertions, 0 deletions
diff --git a/test/test_ipaddr.rb b/test/test_ipaddr.rb
index 7b3a199bf3..e2243dc542 100644
--- a/test/test_ipaddr.rb
+++ b/test/test_ipaddr.rb
@@ -116,6 +116,23 @@ class TC_IPAddr < Test::Unit::TestCase
assert_equal("192.168.2.1", IPAddr.new_ntoh(a.hton).to_s)
end
+ def test_ntop
+ # IPv4
+ assert_equal("192.168.1.1", IPAddr.ntop("\xC0\xA8\x01\x01"))
+ # IPv6
+ assert_equal("0000:0000:0000:0000:0000:0000:0000:0001",
+ IPAddr.ntop("\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x01"))
+
+ # Invalid parameters
+ assert_raise(IPAddr::AddressFamilyError) {
+ IPAddr.ntop("192.168.1.1")
+ }
+
+ assert_raise(IPAddr::AddressFamilyError) {
+ IPAddr.ntop("\xC0\xA8\x01\xFF1")
+ }
+ end
+
def test_ipv4_compat
a = IPAddr.new("::192.168.1.2")
assert_equal("::192.168.1.2", a.to_s)