Browse Source

Add a property for cow_http_hd:parse_accept_encoding/1

Loïc Hoguin 10 years ago
parent
commit
c1af15e981
1 changed files with 22 additions and 0 deletions
  1. 22 0
      src/cow_http_hd.erl

+ 22 - 0
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 = [
 		{<<>>, []},