summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Miller <icy.arctic.fox@gmail.com>2016-11-03 15:39:07 -0600
committerRomain Tartière <romain@blogreen.org>2017-08-30 09:13:22 +0200
commit591ad0d5fd81fc0ad447b67fb4ec04ec40eddcd5 (patch)
tree5c111ffc5d119da709ba5c507ae0e2615e16948c
parent032e8247f7840a490b226d6fbee89b4799b88660 (diff)
downloadipaddress-591ad0d5fd81fc0ad447b67fb4ec04ec40eddcd5.tar.gz
Add tests for #link_local?
-rw-r--r--test/ipaddress/ipv4_test.rb25
-rw-r--r--test/ipaddress/ipv6_test.rb24
2 files changed, 49 insertions, 0 deletions
diff --git a/test/ipaddress/ipv4_test.rb b/test/ipaddress/ipv4_test.rb
index 19264e2..f9bbf9e 100644
--- a/test/ipaddress/ipv4_test.rb
+++ b/test/ipaddress/ipv4_test.rb
@@ -74,6 +74,22 @@ class IPv4Test < Minitest::Test
"10.32.0.1" => ["10.32.0.253", 253],
"192.0.0.0" => ["192.1.255.255", 131072]
}
+
+ @link_local = [
+ "169.254.0.0",
+ "169.254.255.255",
+ "169.254.12.34",
+ "169.254.0.0/16",
+ "169.254.0.0/17"]
+
+ @not_link_local = [
+ "127.0.0.1",
+ "127.0.1.1",
+ "192.168.0.100",
+ "169.255.0.0",
+ "169.254.0.0/15",
+ "0.0.0.0",
+ "255.255.255.255"]
end
@@ -309,6 +325,15 @@ class IPv4Test < Minitest::Test
assert_equal false, @klass.new("192.0.0.2/24").private?
end
+ def test_method_link_local?
+ @link_local.each do |addr|
+ assert_equal true, @klass.new(addr).link_local?
+ end
+ @not_link_local.each do |addr|
+ assert_equal false, @klass.new(addr).link_local?
+ end
+ end
+
def test_method_octet
assert_equal 172, @ip[0]
assert_equal 16, @ip[1]
diff --git a/test/ipaddress/ipv6_test.rb b/test/ipaddress/ipv6_test.rb
index 7eaa765..e29cd40 100644
--- a/test/ipaddress/ipv6_test.rb
+++ b/test/ipaddress/ipv6_test.rb
@@ -44,6 +44,21 @@ class IPv6Test < Minitest::Test
@network = @klass.new "2001:db8:8:800::/64"
@arr = [8193,3512,0,0,8,2048,8204,16762]
@hex = "20010db80000000000080800200c417a"
+
+ @link_local = [
+ "fe80::",
+ "fe80::1",
+ "fe80::208:74ff:feda:625c",
+ "fe80::/64",
+ "fe80::/65"]
+
+ @not_link_local = [
+ "::",
+ "::1",
+ "ff80:03:02:01::",
+ "2001:db8::8:800:200c:417a",
+ "fe80::/63"]
+
end
def test_attribute_address
@@ -216,6 +231,15 @@ class IPv6Test < Minitest::Test
assert_equal false, @ip.loopback?
end
+ def test_method_link_local?
+ @link_local.each do |addr|
+ assert_equal true, @klass.new(addr).link_local?
+ end
+ @not_link_local.each do |addr|
+ assert_equal false, @klass.new(addr).link_local?
+ end
+ end
+
def test_method_network
@networks.each do |addr,net|
ip = @klass.new addr