1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127
|
/*
restinio
*/
#include <catch2/catch.hpp>
#include <restinio/helpers/http_field_parsers/accept-encoding.hpp>
namespace restinio
{
namespace http_field_parsers
{
bool
operator==( const accept_encoding_value_t::item_t & a,
const accept_encoding_value_t::item_t & b ) noexcept
{
return std::tie( a.content_coding, a.weight ) ==
std::tie( b.content_coding, b.weight );
}
} /* namespace http_field_parsers */
} /* namespace restinio */
TEST_CASE( "Accept-Encoding", "[accept-encoding]" )
{
using namespace restinio::http_field_parsers;
using namespace std::string_literals;
{
const auto result = accept_encoding_value_t::try_parse(
"" );
REQUIRE( result );
REQUIRE( result->codings.empty() );
}
{
const auto result = accept_encoding_value_t::try_parse(
"compress" );
REQUIRE( result );
accept_encoding_value_t::item_container_t expected{
{ "compress"s, qvalue_t{ qvalue_t::maximum } }
};
REQUIRE( expected == result->codings );
}
{
const auto result = accept_encoding_value_t::try_parse(
"compress, gzip" );
REQUIRE( result );
accept_encoding_value_t::item_container_t expected{
{ "compress"s, qvalue_t{ qvalue_t::maximum } }
, { "gzip"s, qvalue_t{ qvalue_t::maximum } }
};
REQUIRE( expected == result->codings );
}
{
const auto result = accept_encoding_value_t::try_parse(
"compress ; q=0.5 , gzip" );
REQUIRE( result );
accept_encoding_value_t::item_container_t expected{
{ "compress"s, qvalue_t{ qvalue_t::trusted{500} } }
, { "gzip"s, qvalue_t{ qvalue_t::maximum } }
};
REQUIRE( expected == result->codings );
}
{
const auto result = accept_encoding_value_t::try_parse(
"compress;q=0.5, gzip;q=1" );
REQUIRE( result );
accept_encoding_value_t::item_container_t expected{
{ "compress"s, qvalue_t{ qvalue_t::trusted{500} } }
, { "gzip"s, qvalue_t{ qvalue_t::maximum } }
};
REQUIRE( expected == result->codings );
}
{
const auto result = accept_encoding_value_t::try_parse(
"gzip;q=1.0, identity; q=0.5, *;q=0" );
REQUIRE( result );
accept_encoding_value_t::item_container_t expected{
{ "gzip"s, qvalue_t{ qvalue_t::maximum } }
, { "identity"s, qvalue_t{ qvalue_t::trusted{500} } }
, { "*"s, qvalue_t{ qvalue_t::zero } }
};
REQUIRE( expected == result->codings );
}
{
const auto result = accept_encoding_value_t::try_parse(
"gzip;q=1.0, identity, *;q=0" );
REQUIRE( result );
accept_encoding_value_t::item_container_t expected{
{ "gzip"s, qvalue_t{ qvalue_t::maximum } }
, { "identity"s, qvalue_t{ qvalue_t::maximum } }
, { "*"s, qvalue_t{ qvalue_t::zero } }
};
REQUIRE( expected == result->codings );
}
}
|