summaryrefslogtreecommitdiff
path: root/test/ipaddress_test.rb
diff options
context:
space:
mode:
authorMarco Ceresa <ceresa@gmail.com>2010-03-11 15:20:59 +0000
committerMarco Ceresa <ceresa@gmail.com>2010-03-11 15:20:59 +0000
commit56273314cd614cc3312d0f552caeb3f6e2f56d2b (patch)
treeee013262f8faa7bbe70802d04502694153272fe7 /test/ipaddress_test.rb
parent92d87502c24a8d3529a1468b2a35249cbc565009 (diff)
downloadipaddress-56273314cd614cc3312d0f552caeb3f6e2f56d2b.tar.gz
Completed tests for ipaddress
Diffstat (limited to 'test/ipaddress_test.rb')
-rw-r--r--test/ipaddress_test.rb35
1 files changed, 35 insertions, 0 deletions
diff --git a/test/ipaddress_test.rb b/test/ipaddress_test.rb
index ebfc505..b9ddf9c 100644
--- a/test/ipaddress_test.rb
+++ b/test/ipaddress_test.rb
@@ -1,3 +1,38 @@
require 'test_helper'
+class IPAddressTest < Test::Unit::TestCase
+
+ def setup
+ @valid_ipv4 = "172.16.10.1/24"
+ @valid_ipv6 = "2001:db8::8:800:200c:417a/64"
+ @valid_mapped = "::13.1.68.3"
+
+ @invalid_ipv4 = "10.0.0.256"
+ @invalid_ipv6 = ":1:2:3:4:5:6:7"
+ @invalid_mapped = "::1:2.3.4"
+
+ @ipv4class = IPAddress::IPv4
+ @ipv6class = IPAddress::IPv6
+ @mappedclass = IPAddress::IPv6::Mapped
+
+ @method = Module.method("IPAddress")
+ end
+
+ def test_method_IPAddress
+ assert_nothing_raised {@method.call(@valid_ipv4)}
+ assert_nothing_raised {@method.call(@valid_ipv6)}
+ assert_nothing_raised {@method.call(@valid_mapped)}
+
+ assert_instance_of @ipv4class, @method.call(@valid_ipv4)
+ assert_instance_of @ipv6class, @method.call(@valid_ipv6)
+ assert_instance_of @mappedclass, @method.call(@valid_mapped)
+
+ assert_raise(ArgumentError) {@method.call(@invalid_ipv4)}
+ assert_raise(ArgumentError) {@method.call(@invalid_ipv6)}
+ assert_raise(ArgumentError) {@method.call(@invalid_mapped)}
+
+ end
+
+end
+