wip
This commit is contained in:
parent
434dfed8af
commit
e50e08eefd
|
@ -13,11 +13,31 @@ import (
|
|||
func TestAddParse(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
aDateStr := "2024-11-02"
|
||||
aDate := time.Date(2024, 11, 9, 0, 0, 0, 0, time.UTC)
|
||||
aTimeStr := "12:00"
|
||||
aTime := time.Date(0, 0, 0, 12, 0, 0, 0, time.UTC)
|
||||
aDayStr := "24h"
|
||||
aDay := time.Duration(24) * time.Hour
|
||||
|
||||
flagOn := &command.FlagDate{
|
||||
Name: command.FlagOn,
|
||||
Value: aDate,
|
||||
}
|
||||
flagAt := &command.FlagTime{
|
||||
Name: command.FlagAt,
|
||||
Value: aTime,
|
||||
}
|
||||
flagFor := &command.FlagDuration{
|
||||
Name: command.FlagFor,
|
||||
Value: aDay,
|
||||
}
|
||||
|
||||
cmd := command.AddCmd{}
|
||||
for _, tc := range []struct {
|
||||
name string
|
||||
args []string
|
||||
expAS *command.ArgSet
|
||||
main []string
|
||||
flags map[string]command.Flag
|
||||
expErr bool
|
||||
}{
|
||||
{
|
||||
|
@ -26,56 +46,52 @@ func TestAddParse(t *testing.T) {
|
|||
},
|
||||
{
|
||||
name: "title missing",
|
||||
args: []string{"add", "-on", "2024-11-09"},
|
||||
main: []string{"add"},
|
||||
flags: map[string]command.Flag{
|
||||
command.FlagOn: flagOn,
|
||||
},
|
||||
expErr: true,
|
||||
},
|
||||
{
|
||||
name: "date missing",
|
||||
args: []string{"add", "some", "title"},
|
||||
main: []string{"add", "some", "title"},
|
||||
expErr: true,
|
||||
},
|
||||
{
|
||||
name: "minimal",
|
||||
args: []string{"add", "title", "-on", "2024-11-09"},
|
||||
expAS: &command.ArgSet{
|
||||
Main: "title",
|
||||
Flags: map[string]string{
|
||||
command.FlagOn: "2024-11-09",
|
||||
command.FlagFor: "24h",
|
||||
},
|
||||
main: []string{"add", "title"},
|
||||
flags: map[string]command.Flag{
|
||||
command.FlagOn: flagOn,
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "start",
|
||||
args: []string{"add", "title", "-on", "2024-11-09", "-at", "12:00"},
|
||||
expAS: &command.ArgSet{
|
||||
Main: "title",
|
||||
Flags: map[string]string{
|
||||
command.FlagOn: "2024-11-09",
|
||||
command.FlagAt: "12:00",
|
||||
main: []string{"add", "title"},
|
||||
flags: map[string]command.Flag{
|
||||
command.FlagOn: flagOn,
|
||||
command.FlagAt: flagAt,
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "start and duration",
|
||||
args: []string{"add", "title", "-on", "2024-11-10", "-at", "12:00", "-for", "1h"},
|
||||
expAS: &command.ArgSet{
|
||||
Main: "title",
|
||||
Flags: map[string]string{
|
||||
command.FlagOn: "2024-11-10",
|
||||
command.FlagAt: "12:00",
|
||||
command.FlagFor: "1h",
|
||||
},
|
||||
},
|
||||
},
|
||||
{
|
||||
name: "start without duration",
|
||||
args: []string{"add", "title", "-on", "2024-11-10", "-for", "1h"},
|
||||
expErr: true,
|
||||
},
|
||||
// {
|
||||
// name: "start and duration",
|
||||
// args: []string{"add", "title", "-on", "2024-11-10", "-at", "12:00", "-for", "1h"},
|
||||
// expAS: &command.ArgSet{
|
||||
// Main: "title",
|
||||
// Flags: map[string]string{
|
||||
// command.FlagOn: "2024-11-10",
|
||||
// command.FlagAt: "12:00",
|
||||
// command.FlagFor: "1h",
|
||||
// },
|
||||
// },
|
||||
// },
|
||||
// {
|
||||
// name: "start without duration",
|
||||
// args: []string{"add", "title", "-on", "2024-11-10", "-for", "1h"},
|
||||
// expErr: true,
|
||||
// },
|
||||
} {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
actAS, actErr := cmd.Parse(tc.args)
|
||||
actErr := cmd.Parse(tc.main, tc.flags)
|
||||
if tc.expErr != (actErr != nil) {
|
||||
t.Errorf("exp nil, got %v", actErr)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue