color_test.go 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. package ircclient
  2. import (
  3. "testing"
  4. )
  5. type colortext struct {
  6. Text string
  7. Color int
  8. }
  9. func TestColor(t *testing.T) {
  10. var sent colortext
  11. var expect string
  12. var got string
  13. var plain string
  14. for sent, expect = range map[colortext]string{{Text: "One", Color: 1}: "\x0301One\x0f",
  15. {"Two", 2}: "\x0302Two\x0f",
  16. {"Three", 3}: "\x0303Three\x0f"} {
  17. got = ColorString(sent.Color, sent.Text)
  18. if got != expect {
  19. t.Errorf("Got %#v, expected %#v", got, expect)
  20. }
  21. plain = Stripper(got)
  22. if plain != sent.Text {
  23. t.Errorf("Got %#v, expected %#v", plain, sent.Text)
  24. }
  25. }
  26. }
  27. // DRY - Don't repeat yourself
  28. type Attr struct {
  29. Name string
  30. Func func(string) string
  31. Code string
  32. }
  33. func DryAttributeTest(t *testing.T, attr Attr) {
  34. var sent, expect, got, plain string
  35. var text []string = []string{"One", "Two", "Three"}
  36. for _, sent = range text {
  37. expect = attr.Code + sent + attr.Code
  38. got = attr.Func(sent)
  39. if got != expect {
  40. t.Errorf("%s: Got %q, expected %q", attr.Name, got, expect)
  41. }
  42. plain = Stripper(got)
  43. if plain != sent {
  44. t.Errorf("%s: stripped Got %q, expected %q", attr.Name, plain, sent)
  45. }
  46. }
  47. }
  48. func TestAttributes(t *testing.T) {
  49. Attrs := []Attr{
  50. {"Bold", Bold, "\x02"},
  51. {"Ttalics", Italics, "\x1d"},
  52. {"Underline", Underline, "\x1f"},
  53. {"Strike", Strike, "\x1e"},
  54. {"Reverse", Reverse, "\x16"},
  55. {"Monospace", Monospace, "\x11"},
  56. }
  57. for _, attr := range Attrs {
  58. DryAttributeTest(t, attr)
  59. }
  60. }
  61. /*
  62. func TestColor(t *testing.T) {
  63. var tests map[int]string {
  64. 1: "\x0301%s\x0f",
  65. }
  66. }
  67. */