2021-07-29 07:01:24 +02:00
|
|
|
package command_test
|
|
|
|
|
|
|
|
import (
|
|
|
|
"errors"
|
|
|
|
"strings"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"git.ewintr.nl/go-kit/test"
|
|
|
|
"git.ewintr.nl/gte/cmd/cli/command"
|
|
|
|
"git.ewintr.nl/gte/internal/task"
|
|
|
|
)
|
|
|
|
|
|
|
|
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{},
|
2021-08-20 13:46:56 +02:00
|
|
|
expErr: command.ErrFieldAlreadyUsed,
|
2021-07-29 07:01:24 +02:00
|
|
|
},
|
|
|
|
} {
|
|
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
|
|
args := strings.Split(tc.input, " ")
|
|
|
|
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")
|
|
|
|
})
|
|
|
|
}
|
|
|
|
}
|