diff --git a/bar_test.go b/bar_test.go index 6b1c348..c483f82 100644 --- a/bar_test.go +++ b/bar_test.go @@ -6,51 +6,79 @@ ) func TestFillBar(t *testing.T) { - s := newTestState(80, 60) tests := []struct { termWidth int barWidth int + total int64 + current int64 + barRefill *refill want []byte }{ { termWidth: 1, - barWidth: 60, + barWidth: 100, want: []byte{}, }, { termWidth: 2, - barWidth: 60, + barWidth: 100, + total: 100, + current: 20, want: []byte("[]"), }, { - termWidth: 4, - barWidth: 60, - want: []byte("[=>]"), + termWidth: 20, + barWidth: 100, + total: 100, + current: 20, + want: []byte("[==>---------------]"), }, { - termWidth: 6, - barWidth: 60, - want: []byte("[==>-]"), + termWidth: 50, + barWidth: 100, + total: 100, + current: 20, + want: []byte("[========>---------------------------------------]"), }, { - termWidth: 8, - barWidth: 60, - want: []byte("[====>-]"), + termWidth: 100, + barWidth: 100, + total: 100, + current: 40, + want: []byte("[======================================>-----------------------------------------------------------]"), }, { - termWidth: 80, - barWidth: 60, - want: []byte("[===========================================>--------------]"), + termWidth: 100, + barWidth: 100, + total: 100, + current: 40, + barRefill: &refill{'+', 32}, + want: []byte("[+++++++++++++++++++++++++++++++=======>-----------------------------------------------------------]"), }, { - termWidth: 80, - barWidth: 62, - want: []byte("[============================================>---------------]"), + termWidth: 100, + barWidth: 100, + total: 100, + current: 99, + want: []byte("[=================================================================================================>]"), + }, + { + termWidth: 100, + barWidth: 100, + total: 100, + current: 100, + want: []byte("[==================================================================================================]"), }, } for _, test := range tests { + s := newTestState() s.width = test.barWidth + s.total = test.total + s.current = test.current + if test.barRefill != nil { + s.refill = test.barRefill + } got := draw(s, test.termWidth) if !reflect.DeepEqual(test.want, got) { t.Errorf("Want: %q, Got: %q\n", test.want, got) @@ -58,11 +86,9 @@ } } -func newTestState(total, current int64) *state { +func newTestState() *state { return &state{ format: barFmtRunes{'[', '=', '>', '-', ']'}, - total: total, - current: current, trimLeftSpace: true, trimRightSpace: true, }