package util

import "testing"

func TestQuotePlusParity(t *testing.T) {
	cases := []struct{ in, want string }{
		{"hello world", "hello+world"},
		{"a/b", "a%2Fb"},
		{"q=1&x=2", "q%3D1%26x%3D2"},
		{"~_.-", "~_.-"},
		{"héllo", "h%C3%A9llo"},
		{"100%", "100%25"},
	}
	for _, c := range cases {
		if got := QuotePlus(c.in); got != c.want {
			t.Errorf("QuotePlus(%q) = %q, want %q", c.in, got, c.want)
		}
	}
}

func TestQuoteParity(t *testing.T) {
	cases := []struct{ in, want string }{
		{"hello world", "hello%20world"},
		{"/search/pins/", "/search/pins/"},
		{"a b", "a%20b"},
		{"100%", "100%25"},
	}
	for _, c := range cases {
		if got := Quote(c.in); got != c.want {
			t.Errorf("Quote(%q) = %q, want %q", c.in, got, c.want)
		}
	}
}

func TestSlugify(t *testing.T) {
	cases := []struct{ in, want string }{
		{"Hello World", "hello-world"},
		 {"  trim me  ", "trim-me"},
		{"multi   spaces", "multi-spaces"},
		{"under_score", "under-score"},
		{"special!chars?", "specialchars"},
		{"already-slugged", "already-slugged"},
		{"a--b", "a-b"},
	}
	for _, c := range cases {
		if got := Slugify(c.in); got != c.want {
			t.Errorf("Slugify(%q) = %q, want %q", c.in, got, c.want)
		}
	}
}

func TestFormatDescription(t *testing.T) {
	cases := []struct{ in, want string }{
		{"<p>Hello</p>", "Hello"},
		{"a<br>b", "ab"},
		{"line1\r\nline2", "line1\nline2"},
		{"  spaced  ", "spaced"},
		{"", ""},
	}
	for _, c := range cases {
		if got := FormatDescription(c.in); got != c.want {
			t.Errorf("FormatDescription(%q) = %q, want %q", c.in, got, c.want)
		}
	}
}

func TestUcwords(t *testing.T) {
	if got := Ucwords("hello world"); got != "Hello World" {
		t.Errorf("Ucwords = %q", got)
	}
}
