Skip to content

Commit

Permalink
Fixed an input bug, where due (next|last) week is not captured by a r…
Browse files Browse the repository at this point in the history
…egex (#208)

Co-authored-by: Stuart Skelton <[email protected]>
  • Loading branch information
stuartskelton and Stuart Skelton authored Jul 27, 2020
1 parent 986e2b3 commit f419a18
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
3 changes: 2 additions & 1 deletion ultralist/parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,8 @@ func (p *Parser) hasDue(input string) bool {
r1, _ := regexp.Compile(`due \w+$`)
r2, _ := regexp.Compile(`due \w+ \d+$`)
r3, _ := regexp.Compile(`due \d+ \w+$`)
return (r1.MatchString(input) || r2.MatchString(input) || r3.MatchString(input))
r4, _ := regexp.Compile(`due (last|next) week$`)
return (r1.MatchString(input) || r2.MatchString(input) || r3.MatchString(input) || r4.MatchString(input))
}

// Due is returning the the due date of a todo.
Expand Down
26 changes: 26 additions & 0 deletions ultralist/parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,32 @@ func TestParseSubjectWithDue(t *testing.T) {
}
}

func TestParseSubjectWithDueNextWeek(t *testing.T) {
assert := assert.New(t)
parser := &Parser{}
todo := parser.ParseNewTodo("do this thing due next week")
if todo.Subject != "do this thing" {
t.Error("Expected todo.Subject to equal 'do this thing', got ", todo.Subject)
}

expectedDate := parser.Due("due next week", time.Now())
assert.Equal(expectedDate, todo.Due)
assert.NotNil(todo.Due)
}

func TestParseSubjectWithDueLastWeek(t *testing.T) {
assert := assert.New(t)
parser := &Parser{}
todo := parser.ParseNewTodo("do this thing due last week")
if todo.Subject != "do this thing" {
t.Error("Expected todo.Subject to equal 'do this thing', got ", todo.Subject)
}

expectedDate := parser.Due("due last week", time.Now())
assert.Equal(expectedDate, todo.Due)
assert.NotNil(todo.Due)
}

func TestParseExpandProjects(t *testing.T) {
assert := assert.New(t)
parser := &Parser{}
Expand Down

0 comments on commit f419a18

Please sign in to comment.