hsa-app/internal/receipt/receipt_test.go

38 lines
795 B
Go
Raw Permalink Normal View History

package receipt
import "testing"
func TestParseAmountCents(t *testing.T) {
ok := []struct {
in string
want int64
}{
{"12.34", 1234},
{"0.99", 99},
{"100", 10000},
{"12.3", 1230},
{"12", 1200},
{"1234.00", 123400},
{"$12.34", 1234},
{" 12.34 ", 1234},
{"1,234.56", 123456},
}
for _, tc := range ok {
got, err := ParseAmountCents(tc.in)
if err != nil {
t.Errorf("ParseAmountCents(%q) unexpected error: %v", tc.in, err)
continue
}
if got != tc.want {
t.Errorf("ParseAmountCents(%q) = %d, want %d", tc.in, got, tc.want)
}
}
bad := []string{"", "abc", "12.345", "-5.00", "0", "0.00", "12.3.4", "."}
for _, in := range bad {
if _, err := ParseAmountCents(in); err == nil {
t.Errorf("ParseAmountCents(%q) expected error, got nil", in)
}
}
}