diff options
author | Loïc Hoguin <[email protected]> | 2014-12-15 16:46:12 +0200 |
---|---|---|
committer | Loïc Hoguin <[email protected]> | 2014-12-15 16:46:12 +0200 |
commit | f83befd47d74b739560b2595ea920fa88abff62f (patch) | |
tree | 9c74875a526435f756af0b76ddb316092da50f7f | |
parent | f79ac6ed8a572e41c0eed7d728a8fa04445ed719 (diff) | |
download | cowlib-f83befd47d74b739560b2595ea920fa88abff62f.tar.gz cowlib-f83befd47d74b739560b2595ea920fa88abff62f.tar.bz2 cowlib-f83befd47d74b739560b2595ea920fa88abff62f.zip |
Add a property for cow_http_hd:parse_accept_charset/1
-rw-r--r-- | src/cow_http_hd.erl | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/src/cow_http_hd.erl b/src/cow_http_hd.erl index abc08a4..b9bfc56 100644 --- a/src/cow_http_hd.erl +++ b/src/cow_http_hd.erl @@ -414,6 +414,28 @@ conneg_list_sep(<< $\t, R/bits >>, Acc) -> conneg_list_sep(R, Acc); conneg_list_sep(<< $,, R/bits >>, Acc) -> conneg_list(R, Acc). -ifdef(TEST). +accept_charset() -> + ?LET({C, W}, + {token(), weight()}, + {C, W, iolist_to_binary([C, case W of + undefined -> []; + _ -> [<<";q=">>, qvalue_to_iodata(W)] + end])} + ). + +prop_parse_accept_charset() -> + ?FORALL(L, + non_empty(list(accept_charset())), + begin + << _, AcceptCharset/binary >> = iolist_to_binary([[$,, A] || {_, _, A} <- L]), + ResL = parse_accept_charset(AcceptCharset), + CheckedL = [begin + ResC =:= ?INLINE_LOWERCASE_BC(C) + andalso (ResW =:= W orelse (W =:= undefined andalso ResW =:= 1000)) + end || {{C, W, _}, {ResC, ResW}} <- lists:zip(L, ResL)], + [true] =:= lists:usort(CheckedL) + end). + parse_accept_charset_test_() -> Tests = [ {<<"iso-8859-5, unicode-1-1;q=0.8">>, [ |