mirror of
https://github.com/usememos/memos.git
synced 2025-01-01 18:11:49 +08:00
dbc85fe7e4
* feat: image and link parser * chore: update
79 lines
1,023 B
Go
79 lines
1,023 B
Go
package tokenizer
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestTokenize(t *testing.T) {
|
|
tests := []struct {
|
|
text string
|
|
tokens []*Token
|
|
}{
|
|
{
|
|
text: "*Hello world!",
|
|
tokens: []*Token{
|
|
{
|
|
Type: Star,
|
|
Value: "*",
|
|
},
|
|
{
|
|
Type: Text,
|
|
Value: "Hello",
|
|
},
|
|
{
|
|
Type: Space,
|
|
Value: " ",
|
|
},
|
|
{
|
|
Type: Text,
|
|
Value: "world",
|
|
},
|
|
{
|
|
Type: ExclamationMark,
|
|
Value: "!",
|
|
},
|
|
},
|
|
},
|
|
{
|
|
text: `# hello
|
|
world`,
|
|
tokens: []*Token{
|
|
{
|
|
Type: Hash,
|
|
Value: "#",
|
|
},
|
|
{
|
|
Type: Space,
|
|
Value: " ",
|
|
},
|
|
{
|
|
Type: Text,
|
|
Value: "hello",
|
|
},
|
|
{
|
|
Type: Space,
|
|
Value: " ",
|
|
},
|
|
{
|
|
Type: Newline,
|
|
Value: "\n",
|
|
},
|
|
{
|
|
Type: Space,
|
|
Value: " ",
|
|
},
|
|
{
|
|
Type: Text,
|
|
Value: "world",
|
|
},
|
|
},
|
|
},
|
|
}
|
|
|
|
for _, test := range tests {
|
|
result := Tokenize(test.text)
|
|
require.Equal(t, test.tokens, result)
|
|
}
|
|
}
|