bbcode - 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
17 b := bbcode.New(types...)
18
19 var buf bytes.Buffer
20
21 for n, test := range tests {
22 buf.Reset()
23
24 if err := b.ConvertString(&buf, test.Input); err != nil {
25 t.Errorf("test %d: unexpected error: %s", n+1, err)
26 } else if res := buf.String(); res != test.Output {
27 t.Errorf("test %d: expecting %q, got %q", n+1, test.Output, res)
28 }
29 }
30 }
31
32 type attrinout struct {
33 Input string
34 Output []byte
35 }
36
37 func testAttr(t *testing.T, tests []attrinout) {
38 t.Parallel()
39
40 for n, test := range tests {
41 if output := Colours.AttrFilter(test.Input); !bytes.Equal(test.Output, output) {
42 t.Errorf("test %d: expecting %s, got %s", n+1, test.Output, output)
43 }
44 }
45 }
46