From 21e970b0d7b3d41ebda96e9261b0644f73358a58 Mon Sep 17 00:00:00 2001 From: Constantin Rack Date: Sat, 7 Nov 2015 08:59:37 +0100 Subject: [PATCH 1/2] Problem: no test for invalid IPv6 mask --- test/cidr_test.exs | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/cidr_test.exs b/test/cidr_test.exs index 977863e..e1877e4 100644 --- a/test/cidr_test.exs +++ b/test/cidr_test.exs @@ -34,6 +34,10 @@ defmodule CIDRTest do assert "127.0.0.1/24" |> CIDR.parse |> CIDR.is_cidr? end + test "Do not parse ::1/256" do + assert "::1/256" |> CIDR.parse == {:error, "Invalid mask 256"} + end + test "Parse of single IP should return exactly 1 host" do cidr1 = CIDR.parse("127.0.0.1") assert cidr1.hosts == 1 From 838716fc30ab5e85f5f16ed8c45e98442f01455f Mon Sep 17 00:00:00 2001 From: Constantin Rack Date: Sat, 7 Nov 2015 09:08:10 +0100 Subject: [PATCH 2/2] Problem: no test for start and end of range --- test/cidr_test.exs | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/test/cidr_test.exs b/test/cidr_test.exs index e1877e4..a514818 100644 --- a/test/cidr_test.exs +++ b/test/cidr_test.exs @@ -38,6 +38,18 @@ defmodule CIDRTest do assert "::1/256" |> CIDR.parse == {:error, "Invalid mask 256"} end + test "Start and end of IPv4 address range" do + cidr = "127.0.0.1/24" |> CIDR.parse + assert cidr.start == {127, 0, 0, 0} + assert cidr.end == {127, 0, 0, 255} + end + + test "Start and end of IPv6 address range" do + cidr = "::1/24" |> CIDR.parse + assert cidr.start == {0, 0, 0, 0, 0, 0, 0, 0} + assert cidr.end == {0, 255, 65535, 65535, 65535, 65535, 65535, 65535} + end + test "Parse of single IP should return exactly 1 host" do cidr1 = CIDR.parse("127.0.0.1") assert cidr1.hosts == 1