package ticket_test import ( "testing" "time" "task/internal/ticket" ) func TestParseDurationFlexible(t *testing.T) { cases := []struct { in string want time.Duration }{ {"1h30m", 90 * time.Minute}, {"90m", 90 * time.Minute}, {"1.5h", 90 * time.Minute}, {"2h", 2 * time.Hour}, {"45m", 45 * time.Minute}, {"30s", 30 * time.Second}, {"1:30", 90 * time.Minute}, {" 1h ", time.Hour}, } for _, tc := range cases { got, err := ticket.ParseDurationFlexible(tc.in) if err != nil { t.Fatalf("%q: %v", tc.in, err) } if got != tc.want { t.Fatalf("%q: got %v want %v", tc.in, got, tc.want) } } } func TestParseDurationFlexibleRejects(t *testing.T) { for _, in := range []string{"", "abc", "1:99", "-5m"} { if _, err := ticket.ParseDurationFlexible(in); err == nil { t.Fatalf("%q: expected error", in) } } } func TestFormatDurationHuman(t *testing.T) { cases := []struct { d time.Duration want string }{ {2*time.Hour + 15*time.Minute, "2h15m"}, {3 * time.Hour, "3h"}, {45 * time.Minute, "45m"}, {30 * time.Second, "30s"}, } for _, tc := range cases { if got := ticket.FormatDurationHuman(tc.d); got != tc.want { t.Fatalf("%v: got %q want %q", tc.d, got, tc.want) } } }