package sites import "testing" func TestRehomeText(t *testing.T) { const p = "/preview/0/main/" for in, want := range map[string]string{ ``: ``, ``: ``, ``: ``, ``: ``, ``: ``, ``: ``, ``: ``, ``: ``, `
`: `
`, `
`: ``, } { if got := RehomeText(in, p, false); got != want { t.Errorf("%s\n got %s\nwant %s", in, got, want) } } if got := RehomeText(`a{background:url(/x.png)} `, p, true); got != `a{background:url(/preview/0/main/x.png)} ` { t.Errorf("css: %s", got) } } func TestSlug(t *testing.T) { taken := []Preview{{Branch: "supermarket/page-1", Slug: "supermarket-page-1"}} for branch, want := range map[string]string{ "main": "main", "supermarket/page-1": "supermarket-page-1", "Supermarket/Page_1": "supermarket-page-1-2", "///": "branch", } { if got := Slug(branch, taken); got != want { t.Errorf("%q: %q, want %q", branch, got, want) } } }