Test the end iterator set by Parse{Date,Time,DateTime}()
In other words, check that the unprocessed part of the input is what we expected. Also add some cases where a valid date or time is followed by something.
This commit is contained in:
parent
23b8ec6d9a
commit
4cf335340c
@ -913,13 +913,33 @@ void DateTimeTestCase::TestTimeParse()
|
||||
wxDateTime dt;
|
||||
|
||||
// Parsing standard formats should work.
|
||||
CPPUNIT_ASSERT( dt.ParseTime("12:34:56") );
|
||||
const char* end = dt.ParseTime("12:34:56");
|
||||
CPPUNIT_ASSERT( end );
|
||||
if ( end )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL( "12:34:56", dt.FormatISOTime() );
|
||||
CPPUNIT_ASSERT_EQUAL( "", wxString(end) );
|
||||
}
|
||||
dt.ResetTime();
|
||||
|
||||
// Valid, but followed by something.
|
||||
end = dt.ParseTime("12:34:56 0123 something");
|
||||
CPPUNIT_ASSERT( end );
|
||||
if ( end )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL( "12:34:56", dt.FormatISOTime() );
|
||||
CPPUNIT_ASSERT_EQUAL( " 0123 something", wxString(end) );
|
||||
}
|
||||
dt.ResetTime();
|
||||
|
||||
// Parsing just hours should work too.
|
||||
dt.ResetTime();
|
||||
CPPUNIT_ASSERT( dt.ParseTime("17") );
|
||||
end = dt.ParseTime("17");
|
||||
CPPUNIT_ASSERT( end );
|
||||
if ( end )
|
||||
{
|
||||
CPPUNIT_ASSERT_EQUAL( "17:00:00", dt.FormatISOTime() );
|
||||
CPPUNIT_ASSERT_EQUAL( "", wxString(end) );
|
||||
}
|
||||
|
||||
// Parsing gibberish shouldn't work.
|
||||
CPPUNIT_ASSERT( !dt.ParseTime("bloordyblop") );
|
||||
@ -1219,13 +1239,18 @@ void DateTimeTestCase::TestDateParse()
|
||||
const char *str;
|
||||
Date date; // NB: this should be in UTC
|
||||
bool good;
|
||||
const char* beyondEnd; // what remains unprocessed of the input
|
||||
} parseTestDates[] =
|
||||
{
|
||||
{ "21 Mar 2006", { 21, wxDateTime::Mar, 2006 }, true },
|
||||
{ "29 Feb 1976", { 29, wxDateTime::Feb, 1976 }, true },
|
||||
{ "Feb 29 1976", { 29, wxDateTime::Feb, 1976 }, true },
|
||||
{ "31/03/06", { 31, wxDateTime::Mar, 6 }, true },
|
||||
{ "31/03/2006", { 31, wxDateTime::Mar, 2006 }, true },
|
||||
{ "21 Mar 2006", { 21, wxDateTime::Mar, 2006 }, true, ""},
|
||||
{ "29 Feb 1976", { 29, wxDateTime::Feb, 1976 }, true, "" },
|
||||
{ "Feb 29 1976", { 29, wxDateTime::Feb, 1976 }, true, "" },
|
||||
{ "31/03/06", { 31, wxDateTime::Mar, 6 }, true, "" },
|
||||
{ "31/03/2006", { 31, wxDateTime::Mar, 2006 }, true, "" },
|
||||
|
||||
// valid, but followed by something
|
||||
{ "Dec 31 1979 was the end of 70s",
|
||||
{ 31, wxDateTime::Dec, 1979 }, true, "was the end of 70s" },
|
||||
|
||||
// some invalid ones too
|
||||
{ "29 Feb 2006" },
|
||||
@ -1255,6 +1280,7 @@ void DateTimeTestCase::TestDateParse()
|
||||
);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( parseTestDates[n].date.DT(), dt );
|
||||
CPPUNIT_ASSERT_EQUAL( wxString(parseTestDates[n].beyondEnd), wxString(end) );
|
||||
}
|
||||
else // failed to parse
|
||||
{
|
||||
@ -1357,18 +1383,21 @@ void DateTimeTestCase::TestDateTimeParse()
|
||||
const char *str;
|
||||
Date date; // NB: this should be in UTC
|
||||
bool good;
|
||||
const char *beyondEnd; // what remains unprocessed of the input
|
||||
} parseTestDates[] =
|
||||
{
|
||||
{
|
||||
"Thu 22 Nov 2007 07:40:00 PM",
|
||||
{ 22, wxDateTime::Nov, 2007, 19, 40, 0 },
|
||||
true
|
||||
true,
|
||||
""
|
||||
},
|
||||
|
||||
{
|
||||
"2010-01-04 14:30",
|
||||
{ 4, wxDateTime::Jan, 2010, 14, 30, 0 },
|
||||
true
|
||||
true,
|
||||
""
|
||||
},
|
||||
|
||||
{
|
||||
@ -1381,15 +1410,33 @@ void DateTimeTestCase::TestDateTimeParse()
|
||||
{
|
||||
"bloordyblop",
|
||||
{ 1, wxDateTime::Jan, 9999, 0, 0, 0},
|
||||
false
|
||||
false,
|
||||
"bloordyblop"
|
||||
},
|
||||
|
||||
{
|
||||
"2022-03-09 19:12:05 and some text after space",
|
||||
{ 9, wxDateTime::Mar, 2022, 19, 12, 5, -1 },
|
||||
true,
|
||||
" and some text after space"
|
||||
},
|
||||
|
||||
{
|
||||
// something other than a space right after time
|
||||
"2022-03-09 19:12:05AAaaaa",
|
||||
{ 9, wxDateTime::Mar, 2022, 19, 12, 5, -1 },
|
||||
true,
|
||||
"AAaaaa"
|
||||
},
|
||||
|
||||
{
|
||||
"2012-01-01 10:12:05 +0100",
|
||||
{ 1, wxDateTime::Jan, 2012, 10, 12, 5, -1 },
|
||||
true // ParseDateTime does know yet +0100, but
|
||||
true, // ParseDateTime does know yet +0100, but
|
||||
// ignoring that, parsing still succeeds
|
||||
" +0100"
|
||||
},
|
||||
|
||||
};
|
||||
|
||||
wxGCC_WARNING_RESTORE(missing-field-initializers)
|
||||
@ -1412,6 +1459,7 @@ void DateTimeTestCase::TestDateTimeParse()
|
||||
);
|
||||
|
||||
CPPUNIT_ASSERT_EQUAL( parseTestDates[n].date.DT(), dt );
|
||||
CPPUNIT_ASSERT_EQUAL( wxString(parseTestDates[n].beyondEnd), wxString(end) );
|
||||
}
|
||||
else // failed to parse
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user