123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158 |
- package ircclient
- import (
- "testing"
- )
- type colortext struct {
- Text string
- Color int
- }
- func TestColor(t *testing.T) {
- var sent colortext
- var expect string
- var got string
- var plain string
- for sent, expect = range map[colortext]string{{Text: "One", Color: 1}: "\x0301One\x0f",
- {"Two", 2}: "\x0302Two\x0f",
- {"Three", 3}: "\x0303Three\x0f"} {
- got = ColorString(sent.Color, sent.Text)
- if got != expect {
- t.Errorf("Got %#v, expected %#v", got, expect)
- }
- plain = Stripper(got)
- if plain != sent.Text {
- t.Errorf("Got %#v, expected %#v", plain, sent.Text)
- }
- }
- }
- // DRY - Don't repeat yourself
- type Attr struct {
- Name string
- Func func(string) string
- Code string
- }
- func DryAttributeTest(t *testing.T, attr Attr) {
- var sent, expect, got, plain string
- var text []string = []string{"One", "Two", "Three"}
- for _, sent = range text {
- expect = attr.Code + sent + attr.Code
- got = attr.Func(sent)
- if got != expect {
- t.Errorf("%s: Got %#v, expected %#v", attr.Name, got, expect)
- }
- plain = Stripper(got)
- if plain != sent {
- t.Errorf("%s: Got %#v, expected %#v", attr.Name, got, expect)
- }
- }
- }
- func TestAttributes(t *testing.T) {
- Attrs := []Attr{
- {"Bold", Bold, "\x02"},
- {"Ttalics", Italics, "\x1d"},
- }
- for _, attr := range Attrs {
- DryAttributeTest(t, attr)
- }
- /*
- var sent string
- var expect string
- var got string
- var plain string
- for sent, expect = range map[string]string{"One": "\x02One\x02",
- "Two": "\x02Two\x02",
- "Three": "\x02Three\x02"} {
- got = Bold(sent)
- if got != expect {
- t.Errorf("Got %#v, expected %#v", got, expect)
- }
- plain = Stripper(got)
- if plain != sent {
- t.Errorf("Got %#v, expected %#v", plain, sent)
- }
- }
- */
- }
- func TestItalics(t *testing.T) {
- var sent string
- var expect string
- var got string
- var plain string
- for sent, expect = range map[string]string{"One": "\x1dOne\x1d",
- "Two": "\x1dTwo\x1d",
- "Three": "\x1dThree\x1d"} {
- got = Italics(sent)
- if got != expect {
- t.Errorf("Got %#v, expected %#v", got, expect)
- }
- plain = Stripper(got)
- if plain != sent {
- t.Errorf("Got %s, expected %s", plain, sent)
- }
- }
- }
- func TestUnderline(t *testing.T) {
- var sent string
- var expect string
- var got string
- var plain string
- for sent, expect = range map[string]string{"One": "\x16One\x16",
- "Two": "\x16Two\x16",
- "Three": "\x16Three\x16"} {
- got = Underline(sent)
- if got != expect {
- t.Errorf("Got %#v, expected %#v", got, expect)
- }
- plain = Stripper(got)
- if plain != sent {
- t.Errorf("Got %#v, expected %#v", plain, sent)
- }
- }
- }
- func TestStrike(t *testing.T) {
- var sent string
- var expect string
- var got string
- var plain string
- for sent, expect = range map[string]string{"One": "\x1eOne\x1e",
- "Two": "\x1eTwo\x1e",
- "Three": "\x1eThree\x1e"} {
- got = Strike(sent)
- if got != expect {
- t.Errorf("Got %#v, expected %#v", got, expect)
- }
- plain = Stripper(got)
- if plain != sent {
- t.Errorf("Got %#v, expected %#v", plain, sent)
- }
- }
- }
- func TestMono(t *testing.T) {
- var sent string
- var expect string
- var got string
- var plain string
- for sent, expect = range map[string]string{"One": "\x11One\x11",
- "Two": "\x11Two\x11",
- "Three": "\x11Three\x11"} {
- got = Monospace(sent)
- if got != expect {
- t.Errorf("Got %#v, expected %#v", got, expect)
- }
- plain = Stripper(got)
- if plain != sent {
- t.Errorf("Got %#v, expected %#v", plain, sent)
- }
- }
- }
|