aboutsummaryrefslogtreecommitdiffstats
path: root/todolist/parser_test.go
diff options
context:
space:
mode:
authorGrant Ammons <gammons@gmail.com>2016-04-30 08:45:49 -0400
committerGrant Ammons <gammons@gmail.com>2016-04-30 08:45:49 -0400
commitef9427646b9464d1f8c376f75741e737117a1a83 (patch)
treeba3912135e071cd2c7b77e746126cc5eae67ccfb /todolist/parser_test.go
parent695c60e3f58d831e4b05aa35114adff7e1c46d23 (diff)
Handle parsing dates, and printing them
Diffstat (limited to 'todolist/parser_test.go')
-rw-r--r--todolist/parser_test.go58
1 files changed, 44 insertions, 14 deletions
diff --git a/todolist/parser_test.go b/todolist/parser_test.go
index 1ab2826..9a2732c 100644
--- a/todolist/parser_test.go
+++ b/todolist/parser_test.go
@@ -6,11 +6,12 @@ import (
"time"
"github.com/jinzhu/now"
+ "github.com/stretchr/testify/assert"
)
func TestParseSubject(t *testing.T) {
parser := &Parser{}
- todo := parser.Parse("do this thing")
+ todo := parser.ParseNewTodo("do this thing")
if todo.Subject != "do this thing" {
t.Error("Expected todo.Subject to equal 'do this thing'")
}
@@ -18,7 +19,7 @@ func TestParseSubject(t *testing.T) {
func TestParseSubjectWithDue(t *testing.T) {
parser := &Parser{}
- todo := parser.Parse("do this thing due tomorrow")
+ todo := parser.ParseNewTodo("do this thing due tomorrow")
if todo.Subject != "do this thing" {
t.Error("Expected todo.Subject to equal 'do this thing', got ", todo.Subject)
}
@@ -26,7 +27,7 @@ func TestParseSubjectWithDue(t *testing.T) {
func TestParseProjects(t *testing.T) {
parser := &Parser{}
- todo := parser.Parse("do this thing +proj1 +proj2 due tomorrow")
+ todo := parser.ParseNewTodo("do this thing +proj1 +proj2 due tomorrow")
if len(todo.Projects) != 2 {
t.Error("Expected Projects length to be 2")
}
@@ -40,7 +41,7 @@ func TestParseProjects(t *testing.T) {
func TestParseContexts(t *testing.T) {
parser := &Parser{}
- todo := parser.Parse("do this thing with @bob and @mary due tomorrow")
+ todo := parser.ParseNewTodo("do this thing with @bob and @mary due tomorrow")
if len(todo.Contexts) != 2 {
t.Error("Expected Projects length to be 2")
}
@@ -54,20 +55,55 @@ func TestParseContexts(t *testing.T) {
func TestDueToday(t *testing.T) {
parser := &Parser{}
- todo := parser.Parse("do this thing with @bob and @mary due today")
- if todo.FormattedDue != now.BeginningOfDay() {
+ todo := parser.ParseNewTodo("do this thing with @bob and @mary due today")
+ if todo.Due != now.BeginningOfDay().Format("2006-01-02") {
fmt.Println("Date is different", todo.Due, time.Now())
}
}
func TestDueTomorrow(t *testing.T) {
parser := &Parser{}
- todo := parser.Parse("do this thing with @bob and @mary due tomorrow")
- if todo.FormattedDue != now.BeginningOfDay().AddDate(0, 0, 1) {
+ todo := parser.ParseNewTodo("do this thing with @bob and @mary due tomorrow")
+ if todo.Due != now.BeginningOfDay().AddDate(0, 0, 1).Format("2006-01-02") {
fmt.Println("Date is different", todo.Due, time.Now())
}
}
+func TestMondayOnSunday(t *testing.T) {
+ assert := assert.New(t)
+ parser := &Parser{}
+ now, _ := time.Parse("2006-01-02", "2016-04-24")
+ assert.Equal("2016-04-25", parser.monday(now))
+}
+
+func TestMondayOnMonday(t *testing.T) {
+ assert := assert.New(t)
+ parser := &Parser{}
+ now, _ := time.Parse("2006-01-02", "2016-04-25")
+ assert.Equal("2016-04-25", parser.monday(now))
+}
+
+func TestMondayOnTuesday(t *testing.T) {
+ assert := assert.New(t)
+ parser := &Parser{}
+ now, _ := time.Parse("2006-01-02", "2016-04-26")
+ assert.Equal("2016-05-02", parser.monday(now))
+}
+
+func TestTuesdayOnMonday(t *testing.T) {
+ assert := assert.New(t)
+ parser := &Parser{}
+ now, _ := time.Parse("2006-01-02", "2016-04-25")
+ assert.Equal("2016-04-26", parser.tuesday(now))
+}
+
+func TestTuesdayOnWednesday(t *testing.T) {
+ assert := assert.New(t)
+ parser := &Parser{}
+ now, _ := time.Parse("2006-01-02", "2016-04-27")
+ assert.Equal("2016-05-03", parser.tuesday(now))
+}
+
//func TestDueNextWeek(t *testing.T) {
// parser := &Parser{}
//
@@ -75,9 +111,3 @@ func TestDueTomorrow(t *testing.T) {
// todo := parser.Parse("do this thing with @bob and @mary due next week")
// fmt.Println(todo.Due)
//}
-
-func TestDueMonday(t *testing.T) {
- parser := &Parser{}
- todo := parser.Parse("do this thing with @bob and @mary due mon")
- fmt.Println(todo.Due)
-}