优化结构

This commit is contained in:
Yvan
2026-08-28 00:29:40 +08:00
parent 04ff85116c
commit 03a4131f6e
118 changed files with 758 additions and 834 deletions
+25
View File
@@ -0,0 +1,25 @@
package paymentkit
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")
}
}