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
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
package todolist
import (
"fmt"
"strconv"
"testing"
"time"
"github.com/stretchr/testify/assert"
)
func TestAddTodo(t *testing.T) {
assert := assert.New(t)
app := &App{TodoList: &TodoList{}, TodoStore: &MemoryStore{}}
year := strconv.Itoa(time.Now().Year())
app.AddTodo("a do some stuff due may 23")
todo := app.TodoList.FindById(1)
assert.Equal("do some stuff", todo.Subject)
assert.Equal(fmt.Sprintf("%s-05-23", year), todo.Due)
assert.Equal(false, todo.Completed)
assert.Equal(false, todo.Archived)
assert.Equal(false, todo.IsPriority)
assert.Equal("", todo.CompletedDate)
assert.Equal([]string{}, todo.Projects)
assert.Equal([]string{}, todo.Contexts)
}
func TestAddTodoWithEuropeanDates(t *testing.T) {
assert := assert.New(t)
app := &App{TodoList: &TodoList{}, TodoStore: &MemoryStore{}}
app.AddTodo("a do some stuff due 23 may")
todo := app.TodoList.FindById(1)
assert.Equal("do some stuff", todo.Subject)
assert.Equal("2017-05-23", todo.Due)
assert.Equal(false, todo.Completed)
assert.Equal(false, todo.Archived)
assert.Equal(false, todo.IsPriority)
assert.Equal("", todo.CompletedDate)
assert.Equal([]string{}, todo.Projects)
assert.Equal([]string{}, todo.Contexts)
}
func TestListbyProject(t *testing.T) {
assert := assert.New(t)
app := &App{TodoList: &TodoList{}, TodoStore: &MemoryStore{}}
app.Load()
// create three todos w/wo a project
app.AddTodo("this is a test +testme")
app.AddTodo("this is a test +testmetoo @work")
app.AddTodo("this is a test with no projects")
app.CompleteTodo("c 1")
// simulate listTodos
input := "l by p"
filtered := NewFilter(app.TodoList.Todos()).Filter(input)
grouped := app.getGroups(input, filtered)
assert.Equal(3, len(grouped.Groups))
// testme project has 1 todo and its completed
assert.Equal(1, len(grouped.Groups["testme"]))
assert.Equal(true, grouped.Groups["testme"][0].Completed)
// testmetoo project has 1 todo and it has a context
assert.Equal(1, len(grouped.Groups["testmetoo"]))
assert.Equal(1, len(grouped.Groups["testmetoo"][0].Contexts))
assert.Equal("work", grouped.Groups["testmetoo"][0].Contexts[0])
}
func TestListbyContext(t *testing.T) {
assert := assert.New(t)
app := &App{TodoList: &TodoList{}, TodoStore: &MemoryStore{}}
app.Load()
// create three todos w/wo a context
app.AddTodo("this is a test +testme")
app.AddTodo("this is a test +testmetoo @work")
app.AddTodo("this is a test with no projects")
app.CompleteTodo("c 1")
// simulate listTodos
input := "l by c"
filtered := NewFilter(app.TodoList.Todos()).Filter(input)
grouped := app.getGroups(input, filtered)
assert.Equal(2, len(grouped.Groups))
// work context has 1 todo and it has a project of testmetoo
assert.Equal(1, len(grouped.Groups["work"]))
assert.Equal(1, len(grouped.Groups["work"][0].Projects))
assert.Equal("testmetoo", grouped.Groups["work"][0].Projects[0])
// There are two todos with no context
assert.Equal(2, len(grouped.Groups["No contexts"]))
// check to see if the a todos with no context contain a
// completed todo
var hasACompletedTodo bool
for _, todo := range grouped.Groups["No contexts"] {
if todo.Completed {
hasACompletedTodo = true
}
}
assert.Equal(true, hasACompletedTodo)
}
func TestGetIds(t *testing.T) {
assert := assert.New(t)
app := &App{TodoList: &TodoList{}, TodoStore: &MemoryStore{}}
// no valid id here
assert.Equal(0, len(app.getIds("p")))
// one valid value here
assert.Equal([]int{6}, app.getIds("6"))
// lots of single post numbers
assert.Equal([]int{6, 10, 8, 4}, app.getIds("6,10,8,4"))
// a correct range
assert.Equal([]int{6, 7, 8}, app.getIds("6-8"))
// some incorrect ranges
assert.Equal(0, len(app.getIds("6-6")))
assert.Equal(0, len(app.getIds("8-6")))
// some compsite ranges
assert.Equal([]int{5, 6, 7, 8, 10, 11, 9}, app.getIds("5,6-8,10-11,9"))
}
|