package paymentutil

import "testing"

func TestDecimalAmountUsesIntegerMath(t *testing.T) {
	got, err := ParseDecimalAmount("12.34", 100)
	if err != nil || got != 1234 {
		t.Fatalf("ParseDecimalAmount = %d, %v", got, err)
	}
	formatted, err := FormatDecimalAmount(got, 100)
	if err != nil || formatted != "12.34" {
		t.Fatalf("FormatDecimalAmount = %q, %v", formatted, err)
	}
}

func TestDecimalAmountRejectsUnsafeInput(t *testing.T) {
	for _, value := range []string{"-1.00", "1.001", "1.2.3"} {
		if _, err := ParseDecimalAmount(value, 100); err == nil {
			t.Fatalf("ParseDecimalAmount(%q) accepted unsafe input", value)
		}
	}
	if _, err := ParseDecimalAmount("1", 3); err == nil {
		t.Fatal("non power-of-ten scale accepted")
	}
}
