package util import "testing" func TestURLEncodePath(t *testing.T) { tests := []struct{ in, want string }{ {"a/b c", "a/b%20c"}, {"/leading/trailing/", "leading/trailing"}, {"Hatsune Miku [id]", "Hatsune%20Miku%20%5Bid%5D"}, {"plain", "plain"}, } for _, tc := range tests { if got := URLEncodePath(tc.in); got != tc.want { t.Errorf("URLEncodePath(%q) = %q, want %q", tc.in, got, tc.want) } } } func TestFormatClock(t *testing.T) { tests := []struct { in int want string }{ {0, "0:00"}, {65, "1:05"}, {3599, "59:59"}, {3600, "1:00:00"}, {3723, "1:02:03"}, } for _, tc := range tests { if got := FormatClock(tc.in); got != tc.want { t.Errorf("FormatClock(%d) = %q, want %q", tc.in, got, tc.want) } } } func TestFormatBytes(t *testing.T) { tests := []struct { in int64 want string }{ {512, "512 B"}, {1024, "1.0 KiB"}, {1536, "1.5 KiB"}, {1048576, "1.0 MiB"}, } for _, tc := range tests { if got := FormatBytes(tc.in); got != tc.want { t.Errorf("FormatBytes(%d) = %q, want %q", tc.in, got, tc.want) } } }