bbcode: add basic table tests

This commit is contained in:
mappu 2018-04-02 15:57:41 +12:00
parent e0e30372ef
commit 993bd6c4f3
2 changed files with 45 additions and 0 deletions

View File

@ -28,6 +28,10 @@ func NewBBCodeRenderer(baseUrl, ContentedURL, ContentedTag string) *BBCodeRender
}
}
func (this *BBCodeRenderer) Reset() {
this.CodePresent = false
}
type pregReplaceRule struct {
match *regexp.Regexp
replace string

41
bbcode_test.go Normal file
View File

@ -0,0 +1,41 @@
package yatwiki
import (
"testing"
)
func TestBBCode(t *testing.T) {
bbr := NewBBCodeRenderer("http://BASE_URL/", "http://CONTENTED_URL/", "[CONTENTED]")
type testCase struct {
input, expected string
}
testCases := []testCase{
// Test basic functionality
testCase{
`identity`,
`identity`,
},
// Expected youtube format
testCase{
`[youtube]dQw4w9WgXcQ[/youtube]`,
`<iframe width="560" height="315" src="https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ" frameborder="0" allow="autoplay; encrypted-media" allowfullscreen></iframe>`,
},
}
for _, tc := range testCases {
// BBCode renderers are stateful
bbr.Reset()
output := bbr.RenderHTML(tc.input)
if string(output) != tc.expected {
t.Fatalf("Test failed: %s\nResult:\n%s\n", tc.input, output)
}
}
}