package main

import (
	"testing"
	"time"
)

func TestParseDurationMs(t *testing.T) {
	d, err := parseDuration("500ms")
	if err != nil {
		t.Fatal(err)
	}
	if d != 500*time.Millisecond {
		t.Errorf("got %v, want 500ms", d)
	}
}

func TestParseDurationSeconds(t *testing.T) {
	d, err := parseDuration("10s")
	if err != nil {
		t.Fatal(err)
	}
	if d != 10*time.Second {
		t.Errorf("got %v, want 10s", d)
	}
}

func TestParseDurationDecimal(t *testing.T) {
	d, err := parseDuration("1.5s")
	if err != nil {
		t.Fatal(err)
	}
	if d != 1500*time.Millisecond {
		t.Errorf("got %v, want 1.5s", d)
	}
}

func TestParseDurationMinutes(t *testing.T) {
	d, err := parseDuration("1m")
	if err != nil {
		t.Fatal(err)
	}
	if d != time.Minute {
		t.Errorf("got %v, want 1m", d)
	}
}

func TestParseDurationInvalid(t *testing.T) {
	_, err := parseDuration("abc")
	if err == nil {
		t.Error("expected error for invalid duration")
	}
}

func TestParseDurationNoUnit(t *testing.T) {
	_, err := parseDuration("10")
	if err == nil {
		t.Error("expected error for missing unit")
	}
}
