memos/plugin/gomark/parser/code_block_test.go

65 lines
1.2 KiB
Go
Raw Normal View History

package parser
import (
"testing"
"github.com/stretchr/testify/require"
2023-09-17 22:55:13 +08:00
2023-12-12 23:24:02 +08:00
"github.com/usememos/memos/plugin/gomark/ast"
"github.com/usememos/memos/plugin/gomark/parser/tokenizer"
)
func TestCodeBlockParser(t *testing.T) {
tests := []struct {
text string
2023-12-12 23:24:02 +08:00
codeBlock ast.Node
}{
{
text: "```Hello world!```",
codeBlock: nil,
},
{
text: "```\nHello\n```",
2023-12-12 23:24:02 +08:00
codeBlock: &ast.CodeBlock{
Language: "",
Content: "Hello",
},
},
{
text: "```\nHello world!\n```",
2023-12-12 23:24:02 +08:00
codeBlock: &ast.CodeBlock{
Language: "",
Content: "Hello world!",
},
},
{
text: "```java\nHello \n world!\n```",
2023-12-12 23:24:02 +08:00
codeBlock: &ast.CodeBlock{
Language: "java",
Content: "Hello \n world!",
},
},
{
text: "```java\nHello \n world!\n```111",
codeBlock: nil,
},
{
text: "```java\nHello \n world!\n``` 111",
codeBlock: nil,
},
{
text: "```java\nHello \n world!\n```\n123123",
2023-12-12 23:24:02 +08:00
codeBlock: &ast.CodeBlock{
Language: "java",
Content: "Hello \n world!",
},
},
}
for _, test := range tests {
tokens := tokenizer.Tokenize(test.text)
2023-12-12 23:24:02 +08:00
parser := NewCodeBlockParser()
require.Equal(t, test.codeBlock, parser.Parse(tokens))
}
}