color_test.go 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. package door
  2. import (
  3. "testing"
  4. )
  5. func TestColor(t *testing.T) {
  6. ColorMap := map[string][]int{"\x1b[0m": {0},
  7. "\x1b[1m": {1},
  8. "\x1b[0;1;32;45m": {0, 1, 32, 45},
  9. }
  10. for text, code := range ColorMap {
  11. ct := Color(code)
  12. if text != ct {
  13. t.Errorf("Color: Expected %#v (%#v), got %#v", text, code, ct)
  14. }
  15. }
  16. }
  17. func TestColorText(t *testing.T) {
  18. ColorMap := map[string][]int{"BRI WHI": {0, 1, 37},
  19. "RED ON GREEN": {0, 31, 42},
  20. "GREEN ON RED": {0, 32, 41},
  21. "GREE ON MAG": {0, 32, 45},
  22. "WHI ON BLACK": {0, 37, 40}, // BUG? Should be {0}
  23. "WHITE ON BLACK": {0, 37, 40}, // ^ {0}
  24. "BRIGHT WHITE": {0, 1, 37},
  25. "BOLD RED": {0, 1, 31},
  26. "BLUE ON WHITE": {0, 34, 47},
  27. "CYAN ON MAG": {0, 36, 45},
  28. "MAGENTA": {0, 35},
  29. "BRI YELL": {0, 1, 33},
  30. "BRI YELLOW ON BLUE": {0, 1, 33, 44},
  31. "BROWN ON CYAN": {0, 33, 46},
  32. "BLACK ON YELLOW": {0, 30, 43},
  33. "BLINK RED ON BLUE": {0, 5, 31, 44},
  34. "BRIGHT BLINKY BLUE ON GREEN": {0, 1, 5, 34, 42},
  35. "BLI BOLD YEL ON BLUE": {0, 5, 1, 33, 44},
  36. }
  37. for text, code := range ColorMap {
  38. ct := ColorText(text)
  39. cc := Color(code)
  40. if ct != cc {
  41. t.Errorf("ColorText: Expected %#v (%#v), got %#v", cc, code, ct)
  42. }
  43. }
  44. }
  45. func TestColorTextFail(t *testing.T) {
  46. defer func() {
  47. if r := recover(); r == nil {
  48. t.Error("ColorText did not panic on invalid color.")
  49. }
  50. }()
  51. ColorText("BRIGHT BANANA ON FISH")
  52. }