bbcode - bbcodehtml/tags_test.go
1 package bbcodehtml
2
3 import (
4 "bytes"
5 "testing"
6
7 "vimagination.zapto.org/bbcode"
8 )
9
10 type inout struct {
11 Input, Output string
12 }
13
14 func testTag(t *testing.T, tests []inout, types ...bbcode.Handler) {
15 t.Parallel()
16 b := bbcode.New(types...)
17 var buf bytes.Buffer
18 for n, test := range tests {
19 buf.Reset()
20 if err := b.ConvertString(&buf, test.Input); err != nil {
21 t.Errorf("test %d: unexpected error: %s", n+1, err)
22 continue
23 }
24 if res := buf.String(); res != test.Output {
25 t.Errorf("test %d: expecting %q, got %q", n+1, test.Output, res)
26 }
27 }
28 }
29
30 type attrinout struct {
31 Input string
32 Output []byte
33 }
34
35 func testAttr(t *testing.T, tests []attrinout) {
36 t.Parallel()
37 for n, test := range tests {
38 if output := Colours.AttrFilter(test.Input); !bytes.Equal(test.Output, output) {
39 t.Errorf("test %d: expecting %s, got %s", n+1, test.Output, output)
40 }
41 }
42 }
43