bar_test.go 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. package door
  2. import (
  3. "testing"
  4. )
  5. func pctUpdate(pct *int64) func() int64 {
  6. return func() int64 {
  7. return *pct
  8. }
  9. }
  10. func TestBarHalfStep(t *testing.T) {
  11. // This is normally done by door init, but we're skipping that right now
  12. Unicode = true
  13. BOXES = BOXES_UNICODE
  14. BarColor := ColorText("BLUE")
  15. bar := BarLine{Line: Line{DefaultColor: BarColor}, Width: 10, Style: SOLID}
  16. BarSolid := map[int]string{0: BarColor + " ",
  17. 5: BarColor + " ",
  18. 10: BarColor + "\u2588 ",
  19. 20: BarColor + "\u2588\u2588 ",
  20. 25: BarColor + "\u2588\u2588 ",
  21. 50: BarColor + "\u2588\u2588\u2588\u2588\u2588 ",
  22. 75: BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588 ",
  23. 100: BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
  24. }
  25. for pct, text := range BarSolid {
  26. bar.Percent = int64(pct * 100)
  27. got := bar.Output()
  28. if got != text {
  29. t.Errorf("BarHalf: Expected %#v (%d%%), got %#v", text, pct, got)
  30. }
  31. }
  32. BarColor = ColorText("BLA ON WHI")
  33. bar = BarLine{Line: Line{DefaultColor: BarColor}, Width: 10, Style: HALF_STEP}
  34. BarHalf := map[int]string{0: BarColor + " ",
  35. 5: BarColor + "\u258c ",
  36. 6: BarColor + "\u258c ",
  37. 10: BarColor + "\u2588 ",
  38. 20: BarColor + "\u2588\u2588 ",
  39. 25: BarColor + "\u2588\u2588\u258c ",
  40. 26: BarColor + "\u2588\u2588\u258c ",
  41. 50: BarColor + "\u2588\u2588\u2588\u2588\u2588 ",
  42. 75: BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u258c ",
  43. 100: BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
  44. }
  45. for pct, text := range BarHalf {
  46. bar.Percent = int64(pct * 100)
  47. got := bar.Output()
  48. if got != text {
  49. t.Errorf("BarHalf: Expected %#v (%d%%), got %#v", text, pct, got)
  50. }
  51. }
  52. BarColor = ColorText("RED")
  53. bar = BarLine{Line: Line{DefaultColor: BarColor}, Width: 10, Style: GRADIENT}
  54. BarGrad := map[int]string{0: BarColor + " ",
  55. 3: BarColor + "\u2591 ",
  56. 5: BarColor + "\u2592 ",
  57. 8: BarColor + "\u2593 ",
  58. 10: BarColor + "\u2588 ",
  59. 20: BarColor + "\u2588\u2588 ",
  60. 25: BarColor + "\u2588\u2588\u2592 ",
  61. 50: BarColor + "\u2588\u2588\u2588\u2588\u2588 ",
  62. 75: BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2592 ",
  63. 100: BarColor + "\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588\u2588",
  64. }
  65. var percent int64
  66. bar.UpdateP = pctUpdate(&percent)
  67. for pct, text := range BarGrad {
  68. percent = int64(pct * 100)
  69. got := bar.Output()
  70. if got != text {
  71. t.Errorf("BarGradient: Expected %#v (%d%%), got %#v", text, pct, got)
  72. }
  73. }
  74. }