Limit to the first 4 digits when parsing years badly encoded as YYYYMMDD

This commit is contained in:
emeric
2024-02-02 22:58:37 +01:00
parent d3aa11714a
commit 5db91fc5b5
5 changed files with 78 additions and 4 deletions
+37
View File
@@ -76,6 +76,43 @@ TEST(MetaData, parseDate)
}
}
TEST(MetaData, parseYear)
{
using namespace MetaData::Utils;
struct TestCase
{
std::string str;
std::optional<int> result;
} testCases[]
{
{ "1995-05-09", 1995 },
{ "1995", 1995 },
{ "-0", 0 },
{ "0", 0 },
{ "00", 0 },
{ "05", 5 },
{ "050", 50 },
{ "00005", 0 },
{ "-50", -50 },
{ "-", std::nullopt },
{ "", std::nullopt },
{ "a", std::nullopt },
{ "1a", 1 },
{ "12a", 12 },
{ "123a", 123 },
{ "1234a", 1234 },
{ "19951123", 1995 },
{ "199511", 1995 },
};
for (const TestCase& testCase : testCases)
{
const std::optional<int> parsed{ parseYear(testCase.str) };
EXPECT_EQ(parsed, testCase.result) << " str was '" << testCase.str << "'";
}
}
TEST(MetaData, extractPerformerAndRole)
{
using namespace MetaData::Utils;