From c1af15e981801b6baf616f12dc3ddd944a30e4c5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lo=C3=AFc=20Hoguin?= Date: Mon, 15 Dec 2014 16:48:58 +0200 Subject: Add a property for cow_http_hd:parse_accept_encoding/1 --- src/cow_http_hd.erl | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) (limited to 'src/cow_http_hd.erl') diff --git a/src/cow_http_hd.erl b/src/cow_http_hd.erl index b9bfc56..441cd1d 100644 --- a/src/cow_http_hd.erl +++ b/src/cow_http_hd.erl @@ -472,6 +472,28 @@ parse_accept_encoding(Encoding) -> conneg_list(Encoding, []). -ifdef(TEST). +accept_encoding() -> + ?LET({E, W}, + {token(), weight()}, + {E, W, iolist_to_binary([E, case W of + undefined -> []; + _ -> [<<";q=">>, qvalue_to_iodata(W)] + end])} + ). + +prop_parse_accept_encoding() -> + ?FORALL(L, + non_empty(list(accept_encoding())), + begin + << _, AcceptEncoding/binary >> = iolist_to_binary([[$,, A] || {_, _, A} <- L]), + ResL = parse_accept_encoding(AcceptEncoding), + CheckedL = [begin + ResE =:= ?INLINE_LOWERCASE_BC(E) + andalso (ResW =:= W orelse (W =:= undefined andalso ResW =:= 1000)) + end || {{E, W, _}, {ResE, ResW}} <- lists:zip(L, ResL)], + [true] =:= lists:usort(CheckedL) + end). + parse_accept_encoding_test_() -> Tests = [ {<<>>, []}, -- cgit v1.2.3