Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Solution: add tests for invalid IPv6 mask and start/end of range #17

Merged
merged 2 commits into from
Nov 7, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
16 changes: 16 additions & 0 deletions test/cidr_test.exs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,22 @@ 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 "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
Expand Down