mirror of
https://github.com/araddon/dateparse.git
synced 2025-01-19 19:26:09 +08:00
Add tests to verify ambiguous cases
Test cases now validates the following is true: * Fixed https://github.com/araddon/dateparse/issues/91 * Fixed https://github.com/araddon/dateparse/issues/28 (previous commits already addresses these issues, these tests ensure that these issues remain fixed)
This commit is contained in:
parent
df9ae2e32a
commit
8f0059d6da
@ -19,6 +19,7 @@ type dateTest struct {
|
|||||||
err bool
|
err bool
|
||||||
preferDayFirst bool
|
preferDayFirst bool
|
||||||
retryAmbiguous bool
|
retryAmbiguous bool
|
||||||
|
expectAmbiguous bool
|
||||||
}
|
}
|
||||||
|
|
||||||
var testInputs = []dateTest{
|
var testInputs = []dateTest{
|
||||||
@ -847,21 +848,30 @@ func TestParseLayout(t *testing.T) {
|
|||||||
|
|
||||||
var testParseStrict = []dateTest{
|
var testParseStrict = []dateTest{
|
||||||
// dd-mon-yy 13-Feb-03
|
// dd-mon-yy 13-Feb-03
|
||||||
{in: "03-03-14", err: true},
|
{in: "03-03-14", err: true, expectAmbiguous: true},
|
||||||
// mm.dd.yyyy
|
// mm.dd.yyyy
|
||||||
{in: "3.3.2014", err: true},
|
{in: "3.3.2014", err: true, expectAmbiguous: true},
|
||||||
// mm.dd.yy
|
// mm.dd.yy
|
||||||
{in: "08.09.71", err: true},
|
{in: "08.09.71", err: true, expectAmbiguous: true},
|
||||||
// mm/dd/yyyy
|
// mm/dd/yyyy
|
||||||
{in: "3/5/2014", err: true},
|
{in: "3/5/2014", err: true, expectAmbiguous: true},
|
||||||
// mm/dd/yy
|
// mm/dd/yy
|
||||||
{in: "08/08/71", err: true},
|
{in: "08/08/71", err: true, expectAmbiguous: true},
|
||||||
{in: "8/8/71", err: true},
|
{in: "8/8/71", err: true, expectAmbiguous: true},
|
||||||
// mm/dd/yy hh:mm:ss
|
// mm/dd/yy hh:mm:ss
|
||||||
{in: "04/02/2014 04:08:09", err: true},
|
{in: "04/02/2014 04:08:09", err: true, expectAmbiguous: true},
|
||||||
{in: "4/2/2014 04:08:09", err: true},
|
{in: "4/2/2014 04:08:09", err: true, expectAmbiguous: true},
|
||||||
{in: `{"hello"}`, err: true},
|
{in: `{"hello"}`, err: true},
|
||||||
{in: "2009-08-12T22:15Z"},
|
{in: "2009-08-12T22:15Z"},
|
||||||
|
// https://github.com/araddon/dateparse/issues/91
|
||||||
|
{in: "3.31.2014", err: true, expectAmbiguous: true},
|
||||||
|
{in: "3.3.2014", err: true, expectAmbiguous: true},
|
||||||
|
{in: "03.31.2014", err: true, expectAmbiguous: true},
|
||||||
|
{in: "08.21.71", err: true, expectAmbiguous: true},
|
||||||
|
{in: "3/31/2014", err: true, expectAmbiguous: true},
|
||||||
|
{in: "3/3/2014", err: true, expectAmbiguous: true},
|
||||||
|
{in: "03/31/2014", err: true, expectAmbiguous: true},
|
||||||
|
{in: "08/21/71", err: true, expectAmbiguous: true},
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestParseStrict(t *testing.T) {
|
func TestParseStrict(t *testing.T) {
|
||||||
@ -871,6 +881,9 @@ func TestParseStrict(t *testing.T) {
|
|||||||
_, err := ParseStrict(th.in)
|
_, err := ParseStrict(th.in)
|
||||||
if th.err {
|
if th.err {
|
||||||
assert.NotEqual(t, nil, err)
|
assert.NotEqual(t, nil, err)
|
||||||
|
if th.expectAmbiguous {
|
||||||
|
assert.Contains(t, err.Error(), ErrAmbiguousMMDD.Error(), "expected ambiguous")
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
assert.Equal(t, nil, err)
|
assert.Equal(t, nil, err)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user