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
|
#include "rss/rssparser.h"
#include "3rd-party/catch.hpp"
#include "test_helpers/envvar.h"
TEST_CASE("W3CDTF parser extracts date and time from any valid string",
"[rsspp::RssParser]")
{
SECTION("year only") {
REQUIRE(rsspp::RssParser::w3cdtf_to_rfc822("2008") ==
"Tue, 01 Jan 2008 00:00:00 +0000");
}
SECTION("year-month only") {
REQUIRE(rsspp::RssParser::w3cdtf_to_rfc822("2008-12") ==
"Mon, 01 Dec 2008 00:00:00 +0000");
}
SECTION("year-month-day only") {
REQUIRE(rsspp::RssParser::w3cdtf_to_rfc822("2008-12-30") ==
"Tue, 30 Dec 2008 00:00:00 +0000");
}
SECTION("date and hours") {
REQUIRE(rsspp::RssParser::w3cdtf_to_rfc822("2008-12-30T13") ==
"Tue, 30 Dec 2008 13:00:00 +0000");
}
SECTION("date, hours, and minutes") {
REQUIRE(rsspp::RssParser::w3cdtf_to_rfc822("2008-12-30T13:21") ==
"Tue, 30 Dec 2008 13:21:00 +0000");
}
SECTION("date and time, without timezone") {
REQUIRE(rsspp::RssParser::w3cdtf_to_rfc822("2008-12-30T13:21:59") ==
"Tue, 30 Dec 2008 13:21:59 +0000");
}
SECTION("date and time with Z timezone") {
REQUIRE(rsspp::RssParser::w3cdtf_to_rfc822(
"2008-12-30T13:03:15Z") ==
"Tue, 30 Dec 2008 13:03:15 +0000");
}
SECTION("date and time with -08:00 timezone") {
REQUIRE(rsspp::RssParser::w3cdtf_to_rfc822(
"2008-12-30T10:03:15-08:00") ==
"Tue, 30 Dec 2008 18:03:15 +0000");
}
}
TEST_CASE("W3CDTF parser returns empty string on invalid input",
"[rsspp::RssParser]")
{
REQUIRE(rsspp::RssParser::w3cdtf_to_rfc822("foobar") == "");
REQUIRE(rsspp::RssParser::w3cdtf_to_rfc822("-3") == "");
REQUIRE(rsspp::RssParser::w3cdtf_to_rfc822("") == "");
}
TEST_CASE(
"W3C DTF to RFC 822 conversion does not take into account the local "
"timezone (#369)",
"[rsspp::RssParser]")
{
auto input = "2008-12-30T10:03:15-08:00";
auto expected = "Tue, 30 Dec 2008 18:03:15 +0000";
test_helpers::TzEnvVar tzEnv;
// US/Pacific and Australia/Sydney have pretty much opposite DST
// schedules, so for any given moment in time one of the following two
// sections will be observing DST while other won't
SECTION("Timezone Pacific") {
tzEnv.set("US/Pacific");
REQUIRE(rsspp::RssParser::w3cdtf_to_rfc822(input) ==
expected);
}
SECTION("Timezone Australia") {
tzEnv.set("Australia/Sydney");
REQUIRE(rsspp::RssParser::w3cdtf_to_rfc822(input) ==
expected);
}
// During October, both US/Pacific and Australia/Sydney are observing
// DST. Arizona and UTC *never* observe it, though, so the following two
// tests will cover October
SECTION("Timezone Arizona") {
tzEnv.set("US/Arizona");
REQUIRE(rsspp::RssParser::w3cdtf_to_rfc822(input) ==
expected);
}
SECTION("Timezone UTC") {
tzEnv.set("UTC");
REQUIRE(rsspp::RssParser::w3cdtf_to_rfc822(input) ==
expected);
}
}
|