// Copyright 2015 Frustra. All rights reserved.
// Use of this source code is governed by the MIT
// license that can be found in the LICENSE file.
package bbcode
import (
"strings"
"testing"
)
var fullTestInput = `the quick brown [b]fox[/b]:
[url=http://example][img]http://example.png[/img][/url]`
var fullTestOutput = `the quick brown fox:
`
func TestFullBasic(t *testing.T) {
c := NewCompiler(false, false)
input := fullTestInput
output := fullTestOutput
for in, out := range basicTests {
input += in
output += out
}
result := c.Compile(input)
if result != output {
t.Errorf("Failed to compile %s.\nExpected: %s, got: %s\n", input, output, result)
}
}
func BenchmarkFullBasic(b *testing.B) {
c := NewCompiler(false, false)
input := fullTestInput
for in := range basicTests {
input += in
}
b.SetBytes(int64(len(input)))
b.ReportAllocs()
for i := 0; i < b.N; i++ {
c.Compile(input)
}
}
var basicTests = map[string]string{
``: ``,
`[url]http://example.com[/url]`: `http://example.com`,
`[img]http://example.com[/img]`: ``,
`[img][/img]`: ``,
`[url=http://example.com]example[/url]`: `example`,
`[img=http://example.com][/img]`: ``,
`[B]bold[/b]`: `bold`,
`[i]italic[/i]`: `italic`,
`[u]underline[/U]`: `underline`,
`[s]strikethrough[/s]`: `strikethrough`,
`[u][b]something[/b] then [b]something else[/b][/u]`: `something then something else`,
`blank[b][/b]`: `blank`,
"test\nnewline\nnewline": `test
newline
newline`,
"test\n\nnewline": `test
newline`,
"[b]test[/b]\n\nnewline": `test
newline`,
"[b]test\nnewline[/b]": `test
newline`,
"[code][b]some[/b]\n[i]stuff[/i]\n[/quote][/code][b]more[/b]": "
[b]some[/b]\n[i]stuff[/i]\n[/quote]more", "[quote name=Someguy]hello[/quote]": `
Someguy said:hello`, "[center]hello[/center]": `