mirror of
https://github.com/usememos/memos.git
synced 2025-02-24 05:18:57 +08:00
56 lines
1 KiB
Go
56 lines
1 KiB
Go
package parser
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"github.com/usememos/memos/plugin/gomark/ast"
|
|
"github.com/usememos/memos/plugin/gomark/parser/tokenizer"
|
|
"github.com/usememos/memos/plugin/gomark/restore"
|
|
)
|
|
|
|
func TestUnorderedListParser(t *testing.T) {
|
|
tests := []struct {
|
|
text string
|
|
node ast.Node
|
|
}{
|
|
{
|
|
text: "*asd",
|
|
node: nil,
|
|
},
|
|
{
|
|
text: "+ Hello World",
|
|
node: &ast.UnorderedList{
|
|
Symbol: tokenizer.PlusSign,
|
|
Children: []ast.Node{
|
|
&ast.Text{
|
|
Content: "Hello World",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
{
|
|
text: "* **Hello**",
|
|
node: &ast.UnorderedList{
|
|
Symbol: tokenizer.Asterisk,
|
|
Children: []ast.Node{
|
|
&ast.Bold{
|
|
Symbol: "*",
|
|
Children: []ast.Node{
|
|
&ast.Text{
|
|
Content: "Hello",
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
tokens := tokenizer.Tokenize(test.text)
|
|
node, _ := NewUnorderedListParser().Match(tokens)
|
|
require.Equal(t, restore.Restore([]ast.Node{test.node}), restore.Restore([]ast.Node{node}))
|
|
}
|
|
}
|