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.
72 lines
1.1 KiB
Go
72 lines
1.1 KiB
Go
2 years ago
|
package parser
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
|
||
|
"github.com/stretchr/testify/require"
|
||
|
|
||
|
"github.com/usememos/memos/plugin/gomark/ast"
|
||
|
"github.com/usememos/memos/plugin/gomark/parser/tokenizer"
|
||
|
)
|
||
|
|
||
|
func TestParser(t *testing.T) {
|
||
|
tests := []struct {
|
||
|
text string
|
||
|
nodes []ast.Node
|
||
|
}{
|
||
|
{
|
||
|
text: "Hello world!",
|
||
|
nodes: []ast.Node{
|
||
|
&ast.Paragraph{
|
||
|
Children: []ast.Node{
|
||
|
&ast.Text{
|
||
|
Content: "Hello world!",
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
text: "**Hello** world!",
|
||
|
nodes: []ast.Node{
|
||
|
&ast.Paragraph{
|
||
|
Children: []ast.Node{
|
||
|
&ast.Bold{
|
||
|
Symbol: "*",
|
||
|
Content: "Hello",
|
||
|
},
|
||
|
&ast.Text{
|
||
|
Content: " world!",
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
{
|
||
|
text: "Hello **world**!",
|
||
|
nodes: []ast.Node{
|
||
|
&ast.Paragraph{
|
||
|
Children: []ast.Node{
|
||
|
&ast.Text{
|
||
|
Content: "Hello ",
|
||
|
},
|
||
|
&ast.Bold{
|
||
|
Symbol: "*",
|
||
|
Content: "world",
|
||
|
},
|
||
|
&ast.Text{
|
||
|
Content: "!",
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
},
|
||
|
}
|
||
|
|
||
|
for _, test := range tests {
|
||
|
tokens := tokenizer.Tokenize(test.text)
|
||
|
nodes := Parse(tokens)
|
||
|
require.Equal(t, test.nodes, nodes)
|
||
|
}
|
||
|
}
|