33 lines
1.1 KiB
Go
33 lines
1.1 KiB
Go
package store
|
|
|
|
import (
|
|
"strings"
|
|
"testing"
|
|
"time"
|
|
)
|
|
|
|
func TestExpandWikiPrefix(t *testing.T) {
|
|
now := time.Date(2026, 12, 31, 18, 0, 0, 0, time.UTC).In(time.FixedZone("JST", 9*3600))
|
|
for _, tt := range []struct{ template, subject, want string }{
|
|
{"/notes/{YYYY}/{MM}/{DD}/{Subject}", "日本語 / ../ x?y#z", "/notes/2027/01/01/日本語---..--x-y-z"},
|
|
{"/notes/{Subject}", "../", "/notes/untitled"},
|
|
{"/notes/{Subject}", "{YYYY}", "/notes/YYYY"},
|
|
{"/notes", "unused", "/notes"},
|
|
{"", "", ""},
|
|
} {
|
|
got, err := ExpandWikiPrefix(tt.template, tt.subject, now)
|
|
if err != nil || got != tt.want {
|
|
t.Fatalf("%q: %q, %v; want %q", tt.template, got, err, tt.want)
|
|
}
|
|
}
|
|
for _, bad := range []string{"/notes/{YY}", "/notes/{{Subject}}", "/notes/{Subject", "/a/../b/{YYYY}", "/_/api/{Subject}", "relative/{YYYY}"} {
|
|
if _, err := ExpandWikiPrefix(bad, "subject", now); err == nil {
|
|
t.Fatal("accepted", bad)
|
|
}
|
|
}
|
|
got, err := ExpandWikiPrefix("/notes/{Subject}", strings.Repeat("日本語", 200), now)
|
|
if err != nil || len(got) > len("/notes/")+180 || !ValidTaskWikiPrefix(got) {
|
|
t.Fatal(got, err)
|
|
}
|
|
}
|