This commit is contained in:
Erik Winter 2024-11-14 07:31:50 +01:00
parent 434dfed8af
commit e50e08eefd
1 changed files with 53 additions and 37 deletions

View File

@ -13,11 +13,31 @@ import (
func TestAddParse(t *testing.T) { func TestAddParse(t *testing.T) {
t.Parallel() 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{} cmd := command.AddCmd{}
for _, tc := range []struct { for _, tc := range []struct {
name string name string
args []string main []string
expAS *command.ArgSet flags map[string]command.Flag
expErr bool expErr bool
}{ }{
{ {
@ -25,57 +45,53 @@ func TestAddParse(t *testing.T) {
expErr: true, expErr: true,
}, },
{ {
name: "title missing", name: "title missing",
args: []string{"add", "-on", "2024-11-09"}, main: []string{"add"},
flags: map[string]command.Flag{
command.FlagOn: flagOn,
},
expErr: true, expErr: true,
}, },
{ {
name: "date missing", name: "date missing",
args: []string{"add", "some", "title"}, main: []string{"add", "some", "title"},
expErr: true, expErr: true,
}, },
{ {
name: "minimal", name: "minimal",
args: []string{"add", "title", "-on", "2024-11-09"}, main: []string{"add", "title"},
expAS: &command.ArgSet{ flags: map[string]command.Flag{
Main: "title", command.FlagOn: flagOn,
Flags: map[string]string{
command.FlagOn: "2024-11-09",
command.FlagFor: "24h",
},
}, },
}, },
{ {
name: "start", name: "start",
args: []string{"add", "title", "-on", "2024-11-09", "-at", "12:00"}, main: []string{"add", "title"},
expAS: &command.ArgSet{ flags: map[string]command.Flag{
Main: "title", command.FlagOn: flagOn,
Flags: map[string]string{ command.FlagAt: flagAt,
command.FlagOn: "2024-11-09",
command.FlagAt: "12:00",
},
}, },
}, },
{ // {
name: "start and duration", // name: "start and duration",
args: []string{"add", "title", "-on", "2024-11-10", "-at", "12:00", "-for", "1h"}, // args: []string{"add", "title", "-on", "2024-11-10", "-at", "12:00", "-for", "1h"},
expAS: &command.ArgSet{ // expAS: &command.ArgSet{
Main: "title", // Main: "title",
Flags: map[string]string{ // Flags: map[string]string{
command.FlagOn: "2024-11-10", // command.FlagOn: "2024-11-10",
command.FlagAt: "12:00", // command.FlagAt: "12:00",
command.FlagFor: "1h", // command.FlagFor: "1h",
}, // },
}, // },
}, // },
{ // {
name: "start without duration", // name: "start without duration",
args: []string{"add", "title", "-on", "2024-11-10", "-for", "1h"}, // args: []string{"add", "title", "-on", "2024-11-10", "-for", "1h"},
expErr: true, // expErr: true,
}, // },
} { } {
t.Run(tc.name, func(t *testing.T) { 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) { if tc.expErr != (actErr != nil) {
t.Errorf("exp nil, got %v", actErr) t.Errorf("exp nil, got %v", actErr)
} }