From e50e08eefd3797c752b0d0b60d84ead55ee04260 Mon Sep 17 00:00:00 2001 From: Erik Winter Date: Thu, 14 Nov 2024 07:31:50 +0100 Subject: [PATCH] wip --- plan/command/add_test.go | 90 +++++++++++++++++++++++----------------- 1 file changed, 53 insertions(+), 37 deletions(-) diff --git a/plan/command/add_test.go b/plan/command/add_test.go index 650d545..044f5e3 100644 --- a/plan/command/add_test.go +++ b/plan/command/add_test.go @@ -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 }{ { @@ -25,57 +45,53 @@ func TestAddParse(t *testing.T) { expErr: true, }, { - name: "title missing", - args: []string{"add", "-on", "2024-11-09"}, + name: "title missing", + 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) }