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 %q, expected %q", attr.Name, got, expect) } plain = Stripper(got) if plain != sent { t.Errorf("%s: stripped Got %q, expected %q", attr.Name, plain, sent) } } } func TestAttributes(t *testing.T) { Attrs := []Attr{ {"Bold", Bold, "\x02"}, {"Ttalics", Italics, "\x1d"}, {"Underline", Underline, "\x1f"}, {"Strike", Strike, "\x1e"}, {"Reverse", Reverse, "\x16"}, {"Monospace", Monospace, "\x11"}, } for _, attr := range Attrs { DryAttributeTest(t, attr) } } /* func TestColor(t *testing.T) { var tests map[int]string { 1: "\x0301%s\x0f", } } */