From 2416684015948ec02a77d79901429c468f1c0e34 Mon Sep 17 00:00:00 2001 From: Richard Russon Date: Thu, 30 May 2019 10:34:25 +0100 Subject: [PATCH] test: improve test_mutt_date_parse_imap() --- test/date/mutt_date_parse_imap.c | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/test/date/mutt_date_parse_imap.c b/test/date/mutt_date_parse_imap.c index 1bf1880dc..3110cba6e 100644 --- a/test/date/mutt_date_parse_imap.c +++ b/test/date/mutt_date_parse_imap.c @@ -25,6 +25,12 @@ #include "config.h" #include "mutt/mutt.h" +struct ParseImapTest +{ + const char *str; + time_t expected; +}; + void test_mutt_date_parse_imap(void) { // time_t mutt_date_parse_imap(const char *s); @@ -32,4 +38,29 @@ void test_mutt_date_parse_imap(void) { TEST_CHECK(mutt_date_parse_imap(NULL) == 0); } + + // clang-format off + static struct ParseImapTest imap_tests[] = { + // DD-MMM-YYYY HH:MM:SS +ZZzz + { "12-Jan-1999 12:34:56 +0100", 916140896 }, + { " 2-Jan-1999 12:34:56 +0100", 915276896 }, + { "02-Jan-1999 12:34:56 +0100", 915276896 }, + { "12 Jan-1999 12:34:56 +0100", 0 }, + { "12-Jan 1999 12:34:56 +0100", 0 }, + { "12-Jan-1999-12:34:56 +0100", 0 }, + { "12-Jan-1999 12.34:56 +0100", 0 }, + { "12-Jan-1999 12:34.56 +0100", 0 }, + { "12-Jan-1999 12:34:56-+0100", 0 }, + }; + // clang-format on + + { + for (size_t i = 0; i < mutt_array_size(imap_tests); i++) + { + TEST_CASE(imap_tests[i]); + time_t result = mutt_date_parse_imap(imap_tests[i].str); + if (!TEST_CHECK(result == imap_tests[i].expected)) + TEST_MSG("Expected: %ld, Got: %ld", imap_tests[i].expected, result); + } + } } -- 2.40.0