summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMike Mackintosh <m@zyp.io>2015-01-26 16:21:55 -0500
committerMike Mackintosh <m@zyp.io>2015-01-26 16:21:55 -0500
commitf90b36f2da80070411131af985c2af9f236a1685 (patch)
tree223eb31957ab6a3b548aaf6e086c96af1c9b7e6d /test
parentce5b524748759d23790a710fd1adcca6a547d91d (diff)
downloadipaddress-f90b36f2da80070411131af985c2af9f236a1685.tar.gz
added #ntoa unint32 -> ip and tests
Diffstat (limited to 'test')
-rw-r--r--test/ipaddress_test.rb28
-rw-r--r--test/test_helper.rb1
2 files changed, 29 insertions, 0 deletions
diff --git a/test/ipaddress_test.rb b/test/ipaddress_test.rb
index 8e2bb66..c8bf2e7 100644
--- a/test/ipaddress_test.rb
+++ b/test/ipaddress_test.rb
@@ -11,9 +11,28 @@ class IPAddressTest < Test::Unit::TestCase
@invalid_ipv6 = ":1:2:3:4:5:6:7"
@invalid_mapped = "::1:2.3.4"
+ @valid_ipv4_uint32 = [4294967295, # 255.255.255.255
+ 167772160, # 10.0.0.0
+ 3232235520, # 192.168.0.0
+ 0]
+
+ @invalid_ipv4_uint32 = [4294967296, # 256.0.0.0
+ "A294967295", # Invalid uINT
+ -1] # Invalid
+
+
@ipv4class = IPAddress::IPv4
@ipv6class = IPAddress::IPv6
@mappedclass = IPAddress::IPv6::Mapped
+
+ @invalid_ipv4 = ["10.0.0.256",
+ "10.0.0.0.0",
+ "10.0.0",
+ "10.0"]
+
+ @valid_ipv4_range = ["10.0.0.1-254",
+ "10.0.1-254.0",
+ "10.1-254.0.0"]
@method = Module.method("IPAddress")
end
@@ -31,6 +50,15 @@ class IPAddressTest < Test::Unit::TestCase
assert_raise(ArgumentError) {@method.call(@invalid_ipv6)}
assert_raise(ArgumentError) {@method.call(@invalid_mapped)}
+ assert_instance_of @ipv4class, @method.call(@valid_ipv4_uint32[0])
+ assert_instance_of @ipv4class, @method.call(@valid_ipv4_uint32[1])
+ assert_instance_of @ipv4class, @method.call(@valid_ipv4_uint32[2])
+ assert_instance_of @ipv4class, @method.call(@valid_ipv4_uint32[3])
+
+ assert_raise(ArgumentError) {@method.call(@invalid_ipv4_uint32[0])}
+ assert_raise(ArgumentError) {@method.call(@invalid_ipv4_uint32[1])}
+ assert_raise(ArgumentError) {@method.call(@invalid_ipv4_uint32[2])}
+
end
def test_module_method_valid?
diff --git a/test/test_helper.rb b/test/test_helper.rb
index 61e381e..99fd5e9 100644
--- a/test/test_helper.rb
+++ b/test/test_helper.rb
@@ -1,4 +1,5 @@
require 'rubygems'
+require 'minitest/autorun'
require 'test/unit'
$LOAD_PATH.unshift(File.dirname(__FILE__))