1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
package todolist
import (
"fmt"
"testing"
"time"
"github.com/jinzhu/now"
"github.com/stretchr/testify/assert"
)
func TestParseSubject(t *testing.T) {
parser := &Parser{}
todo := parser.ParseNewTodo("do this thing")
if todo.Subject != "do this thing" {
t.Error("Expected todo.Subject to equal 'do this thing'")
}
}
func TestParseSubjectWithDue(t *testing.T) {
parser := &Parser{}
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)
}
}
func TestParseProjects(t *testing.T) {
parser := &Parser{}
todo := parser.ParseNewTodo("do this thing +proj1 +proj2 due tomorrow")
if len(todo.Projects) != 2 {
t.Error("Expected Projects length to be 2")
}
if todo.Projects[0] != "proj1" {
t.Error("todo.Projects[0] should equal 'proj1' but got", todo.Projects[0])
}
if todo.Projects[1] != "proj2" {
t.Error("todo.Projects[1] should equal 'proj2' but got", todo.Projects[1])
}
}
func TestParseContexts(t *testing.T) {
parser := &Parser{}
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")
}
if todo.Contexts[0] != "bob" {
t.Error("todo.Contexts[0] should equal 'mary' but got", todo.Contexts[0])
}
if todo.Contexts[1] != "mary" {
t.Error("todo.Contexts[1] should equal 'mary' but got", todo.Contexts[1])
}
}
func TestDueToday(t *testing.T) {
parser := &Parser{}
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.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{}
//
// fmt.Println("about to parse")
// todo := parser.Parse("do this thing with @bob and @mary due next week")
// fmt.Println(todo.Due)
//}
|