@@ -0,0 +1,24 @@
|
||||
package customer
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestParseMoneyCentsExact(t *testing.T) {
|
||||
cases := map[string]int64{
|
||||
"0": 0,
|
||||
"1": 100,
|
||||
"1.2": 120,
|
||||
"1.20": 120,
|
||||
"499.99": 49999,
|
||||
}
|
||||
for in, want := range cases {
|
||||
got, err := parseMoneyCents(in)
|
||||
if err != nil || got != want {
|
||||
t.Fatalf("parseMoneyCents(%q) = %d, %v; want %d", in, got, err, want)
|
||||
}
|
||||
}
|
||||
for _, in := range []string{"", "-1.00", "+1.00", "1.234", "1,00", "abc"} {
|
||||
if _, err := parseMoneyCents(in); err == nil {
|
||||
t.Fatalf("parseMoneyCents(%q) should fail", in)
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user