diff --git a/decor/percentage_test.go b/decor/percentage_test.go index bbddf5b..a3ad458 100644 --- a/decor/percentage_test.go +++ b/decor/percentage_test.go @@ -56,3 +56,55 @@ }) } } + +func TestPercentageDecor(t *testing.T) { + cases := []struct { + name string + fmt string + current int64 + total int64 + expected string + }{ + { + name: "tot:100 cur:0 fmt:none", + fmt: "", + current: 0, + total: 100, + expected: "0 %", + }, + { + name: "tot:100 cur:10 fmt:none", + fmt: "", + current: 10, + total: 100, + expected: "10 %", + }, + { + name: "tot:100 cur:10 fmt:%.2f", + fmt: "%.2f", + current: 10, + total: 100, + expected: "10.00%", + }, + { + name: "tot:99 cur:10 fmt:%.2f", + fmt: "%.2f", + current: 11, + total: 99, + expected: "11.11%", + }, + } + for _, tc := range cases { + t.Run(tc.name, func(t *testing.T) { + decor := NewPercentage(tc.fmt) + stat := Statistics{ + Total: tc.total, + Current: tc.current, + } + res, _ := decor.Decor(stat) + if res != tc.expected { + t.Fatalf("expected: %q, got: %q\n", tc.expected, res) + } + }) + } +}