From c50de79c4828dbb4f9b5c23bf9e00ea4dea38a01 Mon Sep 17 00:00:00 2001 From: Grant Ammons Date: Mon, 12 Jun 2017 08:13:15 -0400 Subject: Fix #64, parsing a todo with europe date format * the `hasDue` function was not running, and therefore it was not parsing the due date. * Also added the beginnings of a more holistic test approach, using `app_test.go`. --- todolist/parser_test.go | 40 ++++++++++++++++++++++++++++------------ 1 file changed, 28 insertions(+), 12 deletions(-) (limited to 'todolist/parser_test.go') diff --git a/todolist/parser_test.go b/todolist/parser_test.go index f5cc185..476edaa 100644 --- a/todolist/parser_test.go +++ b/todolist/parser_test.go @@ -75,27 +75,27 @@ func TestParseContexts(t *testing.T) { } func TestDueToday(t *testing.T) { + assert := assert.New(t) parser := &Parser{} + expectedDate := bod(time.Now()).Format("2006-01-02") + todo := parser.ParseNewTodo("do this thing with @bob and @mary due today") - if todo.Due != bod(time.Now()).Format("2006-01-02") { - fmt.Println("Date is different", todo.Due, time.Now()) - } + assert.Equal(expectedDate, todo.Due) + todo = parser.ParseNewTodo("do this thing with @bob and @mary due tod") - if todo.Due != bod(time.Now()).Format("2006-01-02") { - fmt.Println("Date is different", todo.Due, time.Now()) - } + assert.Equal(expectedDate, todo.Due) } func TestDueTomorrow(t *testing.T) { + assert := assert.New(t) parser := &Parser{} + expectedDate := bod(time.Now()).AddDate(0, 0, 1).Format("2006-01-02") + todo := parser.ParseNewTodo("do this thing with @bob and @mary due tomorrow") - if todo.Due != bod(time.Now()).AddDate(0, 0, 1).Format("2006-01-02") { - fmt.Println("Date is different", todo.Due, time.Now()) - } + assert.Equal(expectedDate, todo.Due) + todo = parser.ParseNewTodo("do this thing with @bob and @mary due tom") - if todo.Due != bod(time.Now()).AddDate(0, 0, 1).Format("2006-01-02") { - fmt.Println("Date is different", todo.Due, time.Now()) - } + assert.Equal(expectedDate, todo.Due) } func TestDueSpecific(t *testing.T) { @@ -106,6 +106,14 @@ func TestDueSpecific(t *testing.T) { assert.Equal(fmt.Sprintf("%s-06-01", year), todo.Due) } +func TestDueSpecificEuropeanDate(t *testing.T) { + assert := assert.New(t) + parser := &Parser{} + todo := parser.ParseNewTodo("do this thing with @bob and @mary due 1 jun") + year := strconv.Itoa(time.Now().Year()) + assert.Equal(fmt.Sprintf("%s-06-01", year), todo.Due) +} + func TestMondayOnSunday(t *testing.T) { assert := assert.New(t) parser := &Parser{} @@ -149,6 +157,14 @@ func TestDueOnSpecificDate(t *testing.T) { assert.Equal(fmt.Sprintf("%s-06-01", year), parser.Due("due jun 1", time.Now())) } +func TestDueOnSpecificDateEuropeFormat(t *testing.T) { + assert := assert.New(t) + parser := &Parser{} + year := strconv.Itoa(time.Now().Year()) + assert.Equal(fmt.Sprintf("%s-05-02", year), parser.Due("due 2 may", time.Now())) + assert.Equal(fmt.Sprintf("%s-06-01", year), parser.Due("due 1 jun", time.Now())) +} + func TestDueOnSpecificDateEuropean(t *testing.T) { assert := assert.New(t) parser := &Parser{} -- cgit v1.3