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) } } }