memos/server/tag_test.go

48 lines
1.1 KiB
Go
Raw Normal View History

2022-11-12 09:02:44 +08:00
package server
import (
"testing"
)
func TestFindTagListFromMemoContent(t *testing.T) {
tests := []struct {
memoContent string
want []string
}{
{
memoContent: "#tag1 ",
want: []string{"tag1"},
},
{
memoContent: "#tag1 #tag2 ",
want: []string{"tag1", "tag2"},
},
{
memoContent: "#tag1 #tag2 \n#tag3 ",
want: []string{"tag1", "tag2", "tag3"},
},
{
memoContent: "#tag1 #tag2 \n#tag3 #tag4 ",
want: []string{"tag1", "tag2", "tag3", "tag4"},
},
{
memoContent: "#tag1 #tag2 \n#tag3 #tag4 ",
want: []string{"tag1", "tag2", "tag3", "tag4"},
},
2022-11-25 21:51:53 +08:00
{
memoContent: "#tag1 123123#tag2 \n#tag3 #tag4 ",
2022-12-21 23:59:03 +08:00
want: []string{"tag1", "tag2", "tag3", "tag4"},
2022-11-25 21:51:53 +08:00
},
{
memoContent: "#tag1 http://123123.com?123123#tag2 \n#tag3 #tag4 http://123123.com?123123#tag2) ",
2022-12-21 23:59:03 +08:00
want: []string{"tag1", "tag2", "tag2)", "tag3", "tag4"},
2022-11-25 21:51:53 +08:00
},
2022-11-12 09:02:44 +08:00
}
for _, test := range tests {
result := findTagListFromMemoContent(test.memoContent)
if len(result) != len(test.want) {
t.Errorf("Find tag list %s: got result %v, want %v.", test.memoContent, result, test.want)
}
}
}