package handler import "testing" // TestFormatBytes 校验后台「图集原图总大小」的字节格式化(0/负数为「—」)。 func TestFormatBytes(t *testing.T) { cases := []struct { n int64 want string }{ {0, "—"}, {-1, "—"}, {500, "500 B"}, {1024, "1.0 KB"}, {1536, "1.5 KB"}, {1024 * 1024, "1.0 MB"}, {int64(1.5 * 1024 * 1024), "1.5 MB"}, {int64(1.5 * 1024 * 1024 * 1024), "1.5 GB"}, } for _, c := range cases { if got := formatBytes(c.n); got != c.want { t.Errorf("formatBytes(%d) = %q, want %q", c.n, got, c.want) } } }