aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorYAMAMOTO Takashi <[email protected]>2013-08-25 01:34:42 +0900
committerYAMAMOTO Takashi <[email protected]>2013-09-03 02:09:10 +0900
commit43b3c39a0c74f8dc98ad410d170a87ea5d5f1018 (patch)
tree9bf9f144eccdb7c6f77f195ae6ab36c0f8377210
parent77f7427b4162d518bd4c22806e5acdb40f4fa675 (diff)
downloadcowboy-43b3c39a0c74f8dc98ad410d170a87ea5d5f1018.tar.gz
cowboy-43b3c39a0c74f8dc98ad410d170a87ea5d5f1018.tar.bz2
cowboy-43b3c39a0c74f8dc98ad410d170a87ea5d5f1018.zip
add unit test for cowboy_protocol:parse_host/1
-rw-r--r--src/cowboy_protocol.erl21
1 files changed, 21 insertions, 0 deletions
diff --git a/src/cowboy_protocol.erl b/src/cowboy_protocol.erl
index 887e3aa..68a03b1 100644
--- a/src/cowboy_protocol.erl
+++ b/src/cowboy_protocol.erl
@@ -593,3 +593,24 @@ error_terminate(Status, Req, State) ->
terminate(#state{socket=Socket, transport=Transport}) ->
Transport:close(Socket),
ok.
+
+%% Tests.
+
+-ifdef(TEST).
+
+parse_host(RawHost) ->
+ parse_host(RawHost, false, <<>>).
+
+parse_host_test() ->
+ {<<"example.org">>, 8080} = parse_host(<<"example.org:8080">>),
+ {<<"example.org">>, undefined} = parse_host(<<"example.org">>),
+ {<<"192.0.2.1">>, 8080} = parse_host(<<"192.0.2.1:8080">>),
+ {<<"192.0.2.1">>, undefined} = parse_host(<<"192.0.2.1">>),
+ {<<"[2001:db8::1]">>, 8080} = parse_host(<<"[2001:db8::1]:8080">>),
+ {<<"[2001:db8::1]">>, undefined} = parse_host(<<"[2001:db8::1]">>),
+ {<<"[::ffff:192.0.2.1]">>, 8080} =
+ parse_host(<<"[::ffff:192.0.2.1]:8080">>),
+ {<<"[::ffff:192.0.2.1]">>, undefined} =
+ parse_host(<<"[::ffff:192.0.2.1]">>).
+
+-endif.