Files
backend_v2/internal/handler/templates_format_test.go
toom1996 361ffc01af update
2026-09-29 19:59:30 +08:00

26 lines
579 B
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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)
}
}
}