mirror of https://github.com/usememos/memos
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
37 lines
747 B
Go
37 lines
747 B
Go
2 years ago
|
package html
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/require"
|
||
|
|
||
|
"github.com/usememos/memos/plugin/gomark/parser"
|
||
|
"github.com/usememos/memos/plugin/gomark/parser/tokenizer"
|
||
|
)
|
||
|
|
||
|
func TestHTMLRenderer(t *testing.T) {
|
||
|
tests := []struct {
|
||
|
text string
|
||
|
expected string
|
||
|
}{
|
||
|
{
|
||
|
text: "Hello world!",
|
||
|
expected: `<p>Hello world!</p>`,
|
||
|
},
|
||
|
{
|
||
|
text: "> Hello\n> world!",
|
||
|
expected: `<blockquote>Hello<br>world!</blockquote>`,
|
||
|
},
|
||
|
}
|
||
|
|
||
|
for _, test := range tests {
|
||
|
tokens := tokenizer.Tokenize(test.text)
|
||
|
nodes, err := parser.Parse(tokens)
|
||
|
require.NoError(t, err)
|
||
|
actual := NewHTMLRenderer().Render(nodes)
|
||
|
if actual != test.expected {
|
||
|
t.Errorf("expected: %s, actual: %s", test.expected, actual)
|
||
|
}
|
||
|
}
|
||
|
}
|