progress-bar_test.go 527 B

1234567891011121314151617181920212223242526
  1. // License: GPLv3 Copyright: 2022, Kovid Goyal, <kovid at kovidgoyal.net>
  2. package tui
  3. import (
  4. "fmt"
  5. "kitty/tools/wcswidth"
  6. "testing"
  7. )
  8. var _ = fmt.Print
  9. func TestRenderProgressBar(t *testing.T) {
  10. test := func(frac float64, width int) {
  11. b := RenderProgressBar(frac, width)
  12. a := wcswidth.Stringwidth(b)
  13. if a != width {
  14. t.Fatalf("Actual length %d != Expected length %d with fraction: %v\n%s", a, width, frac, b)
  15. }
  16. }
  17. test(0.9376609994848016, 47)
  18. test(0.9459041731066461, 47)
  19. test(0.9500257599175682, 47)
  20. }