util_test.go
| 1 | package util |
| 2 | |
| 3 | import "testing" |
| 4 | |
| 5 | func TestURLEncodePath(t *testing.T) { |
| 6 | tests := []struct{ in, want string }{ |
| 7 | {"a/b c", "a/b%20c"}, |
| 8 | {"/leading/trailing/", "leading/trailing"}, |
| 9 | {"Hatsune Miku [id]", "Hatsune%20Miku%20%5Bid%5D"}, |
| 10 | {"plain", "plain"}, |
| 11 | } |
| 12 | for _, tc := range tests { |
| 13 | if got := URLEncodePath(tc.in); got != tc.want { |
| 14 | t.Errorf("URLEncodePath(%q) = %q, want %q", tc.in, got, tc.want) |
| 15 | } |
| 16 | } |
| 17 | } |
| 18 | |
| 19 | func TestFormatClock(t *testing.T) { |
| 20 | tests := []struct { |
| 21 | in int |
| 22 | want string |
| 23 | }{ |
| 24 | {0, "0:00"}, |
| 25 | {65, "1:05"}, |
| 26 | {3599, "59:59"}, |
| 27 | {3600, "1:00:00"}, |
| 28 | {3723, "1:02:03"}, |
| 29 | } |
| 30 | for _, tc := range tests { |
| 31 | if got := FormatClock(tc.in); got != tc.want { |
| 32 | t.Errorf("FormatClock(%d) = %q, want %q", tc.in, got, tc.want) |
| 33 | } |
| 34 | } |
| 35 | } |
| 36 | |
| 37 | func TestFormatBytes(t *testing.T) { |
| 38 | tests := []struct { |
| 39 | in int64 |
| 40 | want string |
| 41 | }{ |
| 42 | {512, "512 B"}, |
| 43 | {1024, "1.0 KiB"}, |
| 44 | {1536, "1.5 KiB"}, |
| 45 | {1048576, "1.0 MiB"}, |
| 46 | } |
| 47 | for _, tc := range tests { |
| 48 | if got := FormatBytes(tc.in); got != tc.want { |
| 49 | t.Errorf("FormatBytes(%d) = %q, want %q", tc.in, got, tc.want) |
| 50 | } |
| 51 | } |
| 52 | } |
| 53 |