38 lines
1.3 KiB
Go
38 lines
1.3 KiB
Go
package ref
|
|||
|
|
|
||
|
|
import "testing"
|
||
|
|
|
||
|
|
func TestParse(t *testing.T) {
|
||
|
|
for _, s := range []string{
|
||
|
|
"yetano:package/yamase", "yetano:module/yamase/smtpd", "yetano:manual/yamase/mail-domain#dkim",
|
||
|
|
"yetano:manual/yamase-ctl/backup", "yetano:solution/mail-server@1.0.0", "yetano:task/mail.add-domain",
|
||
|
|
"yetano:capability/mail.smtp.inbound", "yetano:bigpicture/story.mail-groupware", "yetano:example/mail-server/personal",
|
||
|
|
} {
|
||
|
|
r, err := Parse(s)
|
||
|
|
if err != nil {
|
||
|
|
t.Errorf("%s: %v", s, err)
|
||
|
|
continue
|
||
|
|
}
|
||
|
|
if r.String() != s {
|
||
|
|
t.Errorf("round trip %s -> %s", s, r.String())
|
||
|
|
}
|
||
|
|
}
|
||
|
|
for _, bad := range []string{"package/yamase", "yetano:", "yetano:nope/x", "yetano:package", "yetano:package/a/b",
|
||
|
|
"yetano:module/x", "yetano:package/../x", "yetano:manual/x", "yetano:package/x#", "yetano:package/x@"} {
|
||
|
|
if _, err := Parse(bad); err == nil {
|
||
|
|
t.Errorf("%q accepted", bad)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestSlug(t *testing.T) {
|
||
|
|
for in, want := range map[string]string{
|
||
|
|
"Schritt 2: Schlüssel erzeugen": "schritt-2-schluessel-erzeugen",
|
||
|
|
"4. Trusted relays, SRS bounces and ereject": "4-trusted-relays-srs-bounces-and-ereject",
|
||
|
|
" Hello World! ": "hello-world",
|
||
|
|
} {
|
||
|
|
if got := Slug(in); got != want {
|
||
|
|
t.Errorf("%q: %q, want %q", in, got, want)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|