tests to ensure more bad formats fail

This commit is contained in:
Aaron Raddon 2018-04-18 17:36:22 -07:00
parent d5da6dcdf6
commit 4b079c6fdd
2 changed files with 19 additions and 1 deletions

View File

@ -45,7 +45,6 @@ const (
dateAlphaWsAlphaYearmaybe dateAlphaWsAlphaYearmaybe
dateWeekdayComma dateWeekdayComma
dateWeekdayAbbrevComma dateWeekdayAbbrevComma
//dateWeekdayAbbrevCommaDash
) )
const ( const (
// Time state // Time state
@ -356,6 +355,7 @@ iterRunes:
i += (bytesConsumed - 1) i += (bytesConsumed - 1)
} }
//gou.Debugf("i=%d r=%s state=%d %s", i, string(r), p.stateDate, datestr)
switch p.stateDate { switch p.stateDate {
case dateStart: case dateStart:
if unicode.IsDigit(r) { if unicode.IsDigit(r) {
@ -421,6 +421,8 @@ iterRunes:
case '年': case '年':
// Chinese Year // Chinese Year
p.stateDate = dateDigitChineseYear p.stateDate = dateDigitChineseYear
case ',':
return nil, fmt.Errorf("Unrecognized format %q", datestr)
default: default:
//if unicode.IsDigit(r) { //if unicode.IsDigit(r) {
continue continue

View File

@ -523,11 +523,27 @@ func TestPStruct(t *testing.T) {
assert.True(t, len(p.ts()) > 0) assert.True(t, len(p.ts()) > 0)
} }
var testParseErrors = []dateTest{
{in: "3", err: true},
{in: `{"hello"}`, err: true},
{in: "2009-15-12T22:15Z", err: true},
{in: "5,000-9,999", err: true},
{in: "xyzq-baad"},
}
func TestParseErrors(t *testing.T) {
for _, th := range testParseErrors {
v, err := ParseAny(th.in)
assert.NotEqual(t, nil, err, "%v for %v", v, th.in)
}
}
var testParseFormat = []dateTest{ var testParseFormat = []dateTest{
// errors // errors
{in: "3", err: true}, {in: "3", err: true},
{in: `{"hello"}`, err: true}, {in: `{"hello"}`, err: true},
{in: "2009-15-12T22:15Z", err: true}, {in: "2009-15-12T22:15Z", err: true},
{in: "5,000-9,999", err: true},
// //
{in: "oct 7, 1970", out: "Jan 2, 2006"}, {in: "oct 7, 1970", out: "Jan 2, 2006"},
// 03 February 2013 // 03 February 2013