mirror of
https://github.com/usememos/memos.git
synced 2025-06-05 22:09:59 +02:00
feat: implement subscript and superscript parsers
This commit is contained in:
47
plugin/gomark/parser/superscript_test.go
Normal file
47
plugin/gomark/parser/superscript_test.go
Normal file
@ -0,0 +1,47 @@
|
||||
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 TestSuperscriptParser(t *testing.T) {
|
||||
tests := []struct {
|
||||
text string
|
||||
superscript ast.Node
|
||||
}{
|
||||
{
|
||||
text: "^Hello world!",
|
||||
superscript: nil,
|
||||
},
|
||||
{
|
||||
text: "^Hello^",
|
||||
superscript: &ast.Superscript{
|
||||
Content: "Hello",
|
||||
},
|
||||
},
|
||||
{
|
||||
text: "^ Hello ^",
|
||||
superscript: &ast.Superscript{
|
||||
Content: " Hello ",
|
||||
},
|
||||
},
|
||||
{
|
||||
text: "^1^ Hello ^ ^",
|
||||
superscript: &ast.Superscript{
|
||||
Content: "1",
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
tokens := tokenizer.Tokenize(test.text)
|
||||
node, _ := NewSuperscriptParser().Parse(tokens)
|
||||
require.Equal(t, restore.Restore([]ast.Node{test.superscript}), restore.Restore([]ast.Node{node}))
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user