39 lines
1.5 KiB
Go
39 lines
1.5 KiB
Go
package vendor
|
|||
|
|
|
||
|
|
import "testing"
|
||
|
|
|
||
|
|
func TestSetFrontmatterName(t *testing.T) {
|
||
|
|
cases := []struct{ name, in, want string }{
|
||
|
|
{"replace", "---\nname: Good Skill\ndescription: d\n---\nbody\n", "---\nname: ideen\ndescription: d\n---\nbody\n"},
|
||
|
|
{"crlf", "---\r\nname: x\r\n---\r\nb", "---\r\nname: ideen\r\n---\r\nb"},
|
||
|
|
{"insert", "---\ndescription: d\n---\n", "---\nname: ideen\ndescription: d\n---\n"},
|
||
|
|
{"no frontmatter", "# Title\n", "---\nname: ideen\n---\n# Title\n"},
|
||
|
|
{"nested name untouched", "---\nmeta:\n name: inner\n---\n", "---\nname: ideen\nmeta:\n name: inner\n---\n"},
|
||
|
|
{"name in body untouched", "---\ndescription: d\n---\nname: body\n", "---\nname: ideen\ndescription: d\n---\nname: body\n"},
|
||
|
|
}
|
||
|
|
for _, c := range cases {
|
||
|
|
if got := setFrontmatterName(c.in, "ideen"); got != c.want {
|
||
|
|
t.Errorf("%s:\n got %q\nwant %q", c.name, got, c.want)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestValidateRenameTarget(t *testing.T) {
|
||
|
|
ok := []struct{ typ, dep string }{
|
||
|
|
{"skills", "code-review"}, {"skills", "a1"}, {"commands", "Review_Things"},
|
||
|
|
}
|
||
|
|
for _, c := range ok {
|
||
|
|
if err := validateRenameTarget(c.typ, "up", c.dep); err != nil {
|
||
|
|
t.Errorf("%s %q should be valid: %v", c.typ, c.dep, err)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
bad := []struct{ typ, dep string }{
|
||
|
|
{"skills", "Code Review"}, {"skills", "code--review"}, {"skills", "-x"}, {"skills", "Gross"},
|
||
|
|
{"commands", "../x"}, {"agents", "a/b"}, {"commands", ".hidden"}, {"skills", ""},
|
||
|
|
}
|
||
|
|
for _, c := range bad {
|
||
|
|
if err := validateRenameTarget(c.typ, "up", c.dep); err == nil {
|
||
|
|
t.Errorf("%s %q should be rejected", c.typ, c.dep)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|