aboutsummaryrefslogtreecommitdiffstats
path: root/todolist
diff options
context:
space:
mode:
authorQuey-Liang Kao <s101062801@m101.nthu.edu.tw>2017-09-13 02:12:46 -0500
committerGitHub <noreply@github.com>2017-09-13 02:12:46 -0500
commit06211d84da190ab9a5e174db9f52672b69f9b3e4 (patch)
tree2b614952391eff191ee4e29e93fffc6837a042ed /todolist
parent10c18a4c528e3d7389dddb90f54ed5571c0d242a (diff)
parent0c2a2f99a9cdcc9acb7d55807330801d58d4c632 (diff)
Merge pull request #93 from NonerKao/bug_add_empty_todo
Fix a bug in ParseNewTodo()
Diffstat (limited to 'todolist')
-rw-r--r--todolist/app_test.go12
-rw-r--r--todolist/parser.go2
2 files changed, 13 insertions, 1 deletions
diff --git a/todolist/app_test.go b/todolist/app_test.go
index 2fb7717..360da43 100644
--- a/todolist/app_test.go
+++ b/todolist/app_test.go
@@ -44,6 +44,18 @@ func TestAddTodoWithEuropeanDates(t *testing.T) {
assert.Equal([]string{}, todo.Contexts)
}
+func TestAddEmptyTodo(t *testing.T) {
+ assert := assert.New(t)
+ app := &App{TodoList: &TodoList{}, TodoStore: &MemoryStore{}}
+
+ app.AddTodo("a")
+ app.AddTodo("a ")
+ app.AddTodo("a\t\t\t\t")
+ app.AddTodo("a\t \t \t \t")
+
+ assert.Equal(len(app.TodoList.Data), 0)
+}
+
func TestListbyProject(t *testing.T) {
assert := assert.New(t)
app := &App{TodoList: &TodoList{}, TodoStore: &MemoryStore{}}
diff --git a/todolist/parser.go b/todolist/parser.go
index cdfb179..d62c77d 100644
--- a/todolist/parser.go
+++ b/todolist/parser.go
@@ -12,7 +12,7 @@ import (
type Parser struct{}
func (p *Parser) ParseNewTodo(input string) *Todo {
- r, _ := regexp.Compile(`^(add|a)(\\ |) `)
+ r, _ := regexp.Compile(`^(add|a)(\s*|)`)
input = r.ReplaceAllString(input, "")
if input == "" {
return nil