mirror of
https://github.com/restic/restic.git
synced 2025-08-21 17:11:00 +00:00
cmd, ui: Deduplicate formatting utilities
This commit is contained in:
33
internal/ui/format_test.go
Normal file
33
internal/ui/format_test.go
Normal file
@@ -0,0 +1,33 @@
|
||||
package ui
|
||||
|
||||
import "testing"
|
||||
|
||||
func TestFormatBytes(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
size uint64
|
||||
want string
|
||||
}{
|
||||
{0, "0 B"},
|
||||
{1025, "1.001 KiB"},
|
||||
{1<<30 + 7, "1.000 GiB"},
|
||||
} {
|
||||
if got := FormatBytes(c.size); got != c.want {
|
||||
t.Errorf("want %q, got %q", c.want, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestFormatPercent(t *testing.T) {
|
||||
for _, c := range []struct {
|
||||
num, denom uint64
|
||||
want string
|
||||
}{
|
||||
{0, 5, "0.00%"},
|
||||
{3, 7, "42.86%"},
|
||||
{99, 99, "100.00%"},
|
||||
} {
|
||||
if got := FormatPercent(c.num, c.denom); got != c.want {
|
||||
t.Errorf("want %q, got %q", c.want, got)
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user