2022-09-28 08:49:25 +02:00
|
|
|
package command_test
|
2021-07-29 07:01:24 +02:00
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
2021-09-19 11:59:26 +02:00
|
|
|
"ewintr.nl/go-kit/test"
|
2022-09-28 08:49:25 +02:00
|
|
|
"ewintr.nl/gte/cmd/cli/command"
|
2021-09-19 11:59:26 +02:00
|
|
|
"ewintr.nl/gte/internal/task"
|
2021-07-29 07:01:24 +02:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestParseTaskFieldArgs(t *testing.T) {
|
|
|
|
for _, tc := range []struct {
|
2021-08-20 13:46:56 +02:00
|
|
|
name string
|
|
|
|
input string
|
2021-08-22 13:29:04 +02:00
|
|
|
expUpdate *task.LocalUpdate
|
2021-08-20 13:46:56 +02:00
|
|
|
expErr error
|
2021-07-29 07:01:24 +02:00
|
|
|
}{
|
|
|
|
{
|
2021-08-22 13:29:04 +02:00
|
|
|
name: "empty",
|
|
|
|
expUpdate: &task.LocalUpdate{
|
|
|
|
Fields: []string{},
|
|
|
|
},
|
2021-07-29 07:01:24 +02:00
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "join action",
|
|
|
|
input: "some things to do",
|
2021-08-22 13:29:04 +02:00
|
|
|
expUpdate: &task.LocalUpdate{
|
|
|
|
Fields: []string{task.FIELD_ACTION},
|
2021-08-20 13:46:56 +02:00
|
|
|
Action: "some things to do",
|
2021-07-29 07:01:24 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "all",
|
|
|
|
input: "project:project do stuff due:2021-08-06",
|
2021-08-22 13:29:04 +02:00
|
|
|
expUpdate: &task.LocalUpdate{
|
|
|
|
Fields: []string{task.FIELD_PROJECT, task.FIELD_DUE, task.FIELD_ACTION},
|
2021-08-20 13:46:56 +02:00
|
|
|
Action: "do stuff",
|
|
|
|
Project: "project",
|
|
|
|
Due: task.NewDate(2021, 8, 6),
|
2021-07-29 07:01:24 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "no action",
|
|
|
|
input: "due:2021-08-06",
|
2021-08-22 13:29:04 +02:00
|
|
|
expUpdate: &task.LocalUpdate{
|
|
|
|
Fields: []string{task.FIELD_DUE},
|
|
|
|
Due: task.NewDate(2021, 8, 6),
|
2021-07-29 07:01:24 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
2021-08-20 13:46:56 +02:00
|
|
|
name: "two projects",
|
|
|
|
input: "project:project1 project:project2",
|
2021-08-22 13:29:04 +02:00
|
|
|
expUpdate: &task.LocalUpdate{},
|
2022-09-28 08:49:25 +02:00
|
|
|
expErr: command.ErrFieldAlreadyUsed,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "abbreviated",
|
|
|
|
input: "p:project1 d:2022-09-28",
|
|
|
|
expUpdate: &task.LocalUpdate{
|
|
|
|
Fields: []string{task.FIELD_PROJECT, task.FIELD_DUE},
|
|
|
|
Project: "project1",
|
|
|
|
Due: task.NewDate(2022, 9, 28),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty project",
|
|
|
|
input: "action project:",
|
|
|
|
expUpdate: &task.LocalUpdate{},
|
|
|
|
expErr: command.ErrInvalidProject,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "empty date",
|
|
|
|
input: "action due:",
|
|
|
|
expUpdate: &task.LocalUpdate{},
|
|
|
|
expErr: command.ErrInvalidDate,
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "url",
|
|
|
|
input: "https://ewintr.nl/something?arg=1",
|
|
|
|
expUpdate: &task.LocalUpdate{
|
|
|
|
Fields: []string{task.FIELD_ACTION},
|
|
|
|
Action: "https://ewintr.nl/something?arg=1",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "misformatted date",
|
|
|
|
input: "d:20-wrong",
|
|
|
|
expUpdate: &task.LocalUpdate{},
|
|
|
|
expErr: command.ErrInvalidDate,
|
2021-07-29 07:01:24 +02:00
|
|
|
},
|
2022-10-17 10:20:18 +02:00
|
|
|
{
|
|
|
|
name: "recur",
|
|
|
|
input: "recur:today,daily",
|
|
|
|
expUpdate: &task.LocalUpdate{
|
|
|
|
Fields: []string{task.FIELD_RECUR},
|
|
|
|
Recur: task.NewRecurrer("today, daily"),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
name: "recurs short",
|
|
|
|
input: "r:today,daily",
|
|
|
|
expUpdate: &task.LocalUpdate{
|
|
|
|
Fields: []string{task.FIELD_RECUR},
|
|
|
|
Recur: task.NewRecurrer("today, daily"),
|
|
|
|
},
|
|
|
|
},
|
2021-07-29 07:01:24 +02:00
|
|
|
} {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
args := strings.Split(tc.input, " ")
|
2022-09-28 08:49:25 +02:00
|
|
|
act, err := command.ParseTaskFieldArgs(args)
|
2021-08-20 13:46:56 +02:00
|
|
|
test.Equals(t, tc.expUpdate, act)
|
2021-07-29 07:01:24 +02:00
|
|
|
test.Assert(t, errors.Is(err, tc.expErr), "wrong err")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|