planner/plan/command/flag_test.go

142 lines
2.4 KiB
Go
Raw Normal View History

2024-10-29 07:22:04 +01:00
package command_test
import (
"testing"
"time"
2024-12-01 10:22:47 +01:00
"go-mod.ewintr.nl/planner/item"
2024-10-29 07:22:04 +01:00
"go-mod.ewintr.nl/planner/plan/command"
)
func TestFlagString(t *testing.T) {
t.Parallel()
valid := "test"
f := command.FlagString{}
if f.IsSet() {
t.Errorf("exp false, got true")
}
if err := f.Set(valid); err != nil {
t.Errorf("exp nil, got %v", err)
}
if !f.IsSet() {
t.Errorf("exp true, got false")
}
act, ok := f.Get().(string)
if !ok {
t.Errorf("exp true, got false")
}
if act != valid {
t.Errorf("exp %v, got %v", valid, act)
}
}
func TestFlagDate(t *testing.T) {
t.Parallel()
2024-12-23 11:30:24 +01:00
valid := item.NewDate(2024, 11, 20)
2024-10-29 07:22:04 +01:00
f := command.FlagDate{}
if f.IsSet() {
t.Errorf("exp false, got true")
}
2024-12-23 11:30:24 +01:00
if err := f.Set(valid.String()); err != nil {
2024-10-29 07:22:04 +01:00
t.Errorf("exp nil, got %v", err)
}
if !f.IsSet() {
t.Errorf("exp true, got false")
}
2024-12-23 11:30:24 +01:00
act, ok := f.Get().(item.Date)
2024-10-29 07:22:04 +01:00
if !ok {
t.Errorf("exp true, got false")
}
2024-12-23 11:30:24 +01:00
if act.String() != valid.String() {
t.Errorf("exp %v, got %v", valid.String(), act.String())
2024-10-29 07:22:04 +01:00
}
}
func TestFlagTime(t *testing.T) {
t.Parallel()
2024-12-23 11:30:24 +01:00
valid := item.NewTime(12, 30)
2024-10-29 07:22:04 +01:00
f := command.FlagTime{}
if f.IsSet() {
t.Errorf("exp false, got true")
}
2024-12-23 11:30:24 +01:00
if err := f.Set(valid.String()); err != nil {
2024-10-29 07:22:04 +01:00
t.Errorf("exp nil, got %v", err)
}
if !f.IsSet() {
t.Errorf("exp true, got false")
}
2024-12-23 11:30:24 +01:00
act, ok := f.Get().(item.Time)
2024-10-29 07:22:04 +01:00
if !ok {
t.Errorf("exp true, got false")
}
2024-12-23 11:30:24 +01:00
if act.String() != valid.String() {
t.Errorf("exp %v, got %v", valid.String(), act.String())
2024-10-29 07:22:04 +01:00
}
}
func TestFlagDurationTime(t *testing.T) {
t.Parallel()
valid := time.Hour
validStr := "1h"
f := command.FlagDuration{}
if f.IsSet() {
t.Errorf("exp false, got true")
}
if err := f.Set(validStr); err != nil {
t.Errorf("exp nil, got %v", err)
}
if !f.IsSet() {
t.Errorf("exp true, got false")
}
act, ok := f.Get().(time.Duration)
if !ok {
t.Errorf("exp true, got false")
}
if act != valid {
t.Errorf("exp %v, got %v", valid, act)
}
}
2024-12-01 10:22:47 +01:00
2024-12-23 11:30:24 +01:00
func TestFlagRecurrer(t *testing.T) {
2024-12-01 10:22:47 +01:00
t.Parallel()
2024-12-23 11:30:24 +01:00
validStr := "2024-12-23, daily"
valid := item.NewRecurrer(validStr)
f := command.FlagRecurrer{}
2024-12-01 10:22:47 +01:00
if f.IsSet() {
t.Errorf("exp false, got true")
}
if err := f.Set(validStr); err != nil {
t.Errorf("exp nil, got %v", err)
}
if !f.IsSet() {
t.Errorf("exp true, got false")
}
2024-12-23 11:30:24 +01:00
act, ok := f.Get().(item.Recurrer)
2024-12-01 10:22:47 +01:00
if !ok {
t.Errorf("exp true, got false")
}
if act != valid {
t.Errorf("exp %v, got %v", valid, act)
}
}