From e009aa2e31893e52c033049b7ae8ca5059474f3b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Tue, 16 Dec 2014 08:52:41 +0200 Subject: Add a property for cow_http_hd:parse_connection/1 --- src/cow_http_hd.erl | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) (limited to 'src') diff --git a/src/cow_http_hd.erl b/src/cow_http_hd.erl index 23d627b..6e70185 100644 --- a/src/cow_http_hd.erl +++ b/src/cow_http_hd.erl @@ -701,6 +701,16 @@ parse_connection(Connection) -> nonempty(token_ci_list(Connection, [])). -ifdef(TEST). +prop_parse_connection() -> + ?FORALL(L, + non_empty(list(token())), + begin + << _, Connection/binary >> = iolist_to_binary([[$,, C] || C <- L]), + ResL = parse_connection(Connection), + CheckedL = [?INLINE_LOWERCASE_BC(Co) =:= ResC || {Co, ResC} <- lists:zip(L, ResL)], + [true] =:= lists:usort(CheckedL) + end). + parse_connection_test_() -> Tests = [ {<<"close">>, [<<"close">>]}, @@ -709,6 +719,12 @@ parse_connection_test_() -> {<<"keep-alive, Upgrade">>, [<<"keep-alive">>, <<"upgrade">>]} ], [{V, fun() -> R = parse_connection(V) end} || {V, R} <- Tests]. + +parse_connection_error_test_() -> + Tests = [ + <<>> + ], + [{V, fun() -> {'EXIT', _} = (catch parse_connection(V)) end} || V <- Tests]. -endif. -ifdef(PERF). -- cgit v1.2.3