0
Fork 0
mirror of https://github.com/ninenines/cowboy.git synced 2025-07-15 20:50:24 +00:00

add unit test for cowboy_protocol:parse_host/1

This commit is contained in:
YAMAMOTO Takashi 2013-08-25 01:34:42 +09:00
parent 77f7427b41
commit 43b3c39a0c

View file

@ -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.