bbcode: add basic table tests
This commit is contained in:
parent
e0e30372ef
commit
993bd6c4f3
@ -28,6 +28,10 @@ func NewBBCodeRenderer(baseUrl, ContentedURL, ContentedTag string) *BBCodeRender
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (this *BBCodeRenderer) Reset() {
|
||||||
|
this.CodePresent = false
|
||||||
|
}
|
||||||
|
|
||||||
type pregReplaceRule struct {
|
type pregReplaceRule struct {
|
||||||
match *regexp.Regexp
|
match *regexp.Regexp
|
||||||
replace string
|
replace string
|
||||||
|
41
bbcode_test.go
Normal file
41
bbcode_test.go
Normal 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)
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user