mirror of
https://github.com/araddon/dateparse.git
synced 2024-11-10 11:51:54 +08:00
tests to ensure more bad formats fail
This commit is contained in:
parent
d5da6dcdf6
commit
4b079c6fdd
@ -45,7 +45,6 @@ const (
|
||||
dateAlphaWsAlphaYearmaybe
|
||||
dateWeekdayComma
|
||||
dateWeekdayAbbrevComma
|
||||
//dateWeekdayAbbrevCommaDash
|
||||
)
|
||||
const (
|
||||
// Time state
|
||||
@ -356,6 +355,7 @@ iterRunes:
|
||||
i += (bytesConsumed - 1)
|
||||
}
|
||||
|
||||
//gou.Debugf("i=%d r=%s state=%d %s", i, string(r), p.stateDate, datestr)
|
||||
switch p.stateDate {
|
||||
case dateStart:
|
||||
if unicode.IsDigit(r) {
|
||||
@ -421,6 +421,8 @@ iterRunes:
|
||||
case '年':
|
||||
// Chinese Year
|
||||
p.stateDate = dateDigitChineseYear
|
||||
case ',':
|
||||
return nil, fmt.Errorf("Unrecognized format %q", datestr)
|
||||
default:
|
||||
//if unicode.IsDigit(r) {
|
||||
continue
|
||||
|
@ -523,11 +523,27 @@ func TestPStruct(t *testing.T) {
|
||||
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{
|
||||
// errors
|
||||
{in: "3", err: true},
|
||||
{in: `{"hello"}`, err: true},
|
||||
{in: "2009-15-12T22:15Z", err: true},
|
||||
{in: "5,000-9,999", err: true},
|
||||
//
|
||||
{in: "oct 7, 1970", out: "Jan 2, 2006"},
|
||||
// 03 February 2013
|
||||
|
Loading…
Reference in New Issue
Block a user