Skip to content

Commit

Permalink
Add missing test for MochiReq:accepted_encodings/1
Browse files Browse the repository at this point in the history
  • Loading branch information
fdmanana committed Mar 11, 2011
1 parent bed3625 commit b5b187b
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/mochiweb_request_tests.erl
Expand Up @@ -60,4 +60,45 @@ accepts_content_type_test() ->
mochiweb_headers:make([{"Accept", "text/html;level=1;q=0.1, text/html"}])),
?assertEqual(true, Req14:accepts_content_type("text/html; level=1")).

accepted_encodings_test() ->
Req1 = mochiweb_request:new(nil, 'GET', "/foo", {1, 1},
mochiweb_headers:make([])),
?assertEqual(["identity"],
Req1:accepted_encodings(["gzip", "identity"])),

Req2 = mochiweb_request:new(nil, 'GET', "/foo", {1, 1},
mochiweb_headers:make([{"Accept-Encoding", "gzip, deflate"}])),
?assertEqual(["gzip", "identity"],
Req2:accepted_encodings(["gzip", "identity"])),

Req3 = mochiweb_request:new(nil, 'GET', "/foo", {1, 1},
mochiweb_headers:make([{"Accept-Encoding", "gzip;q=0.5, deflate"}])),
?assertEqual(["deflate", "gzip", "identity"],
Req3:accepted_encodings(["gzip", "deflate", "identity"])),

Req4 = mochiweb_request:new(nil, 'GET', "/foo", {1, 1},
mochiweb_headers:make([{"Accept-Encoding", "identity, *;q=0"}])),
?assertEqual(["identity"],
Req4:accepted_encodings(["gzip", "deflate", "identity"])),

Req5 = mochiweb_request:new(nil, 'GET', "/foo", {1, 1},
mochiweb_headers:make([{"Accept-Encoding", "gzip; q=0.1, *;q=0"}])),
?assertEqual(["gzip"],
Req5:accepted_encodings(["gzip", "deflate", "identity"])),

Req6 = mochiweb_request:new(nil, 'GET', "/foo", {1, 1},
mochiweb_headers:make([{"Accept-Encoding", "gzip; q=, *;q=0"}])),
?assertEqual(bad_accept_encoding_value,
Req6:accepted_encodings(["gzip", "deflate", "identity"])),

Req7 = mochiweb_request:new(nil, 'GET', "/foo", {1, 1},
mochiweb_headers:make([{"Accept-Encoding", "gzip;q=2.0, *;q=0"}])),
?assertEqual(bad_accept_encoding_value,
Req7:accepted_encodings(["gzip", "identity"])),

Req8 = mochiweb_request:new(nil, 'GET', "/foo", {1, 1},
mochiweb_headers:make([{"Accept-Encoding", "deflate, *;q=0.0"}])),
?assertEqual([],
Req8:accepted_encodings(["gzip", "identity"])).

-endif.

0 comments on commit b5b187b

Please sign in to comment.