package threadspost

import "testing"

func TestClampPublish(t *testing.T) {
	var long string
	for range MaxPublishRunes + 10 {
		long += "字"
	}
	clamped := ClampPublish(long)
	if RuneLen(clamped) != MaxPublishRunes {
		t.Fatalf("expected %d runes, got %d", MaxPublishRunes, RuneLen(clamped))
	}
}

func TestValidatePublish(t *testing.T) {
	if err := ValidatePublish(""); err == nil {
		t.Fatal("expected empty error")
	}
	if err := ValidatePublish(string(make([]rune, MaxPublishRunes+1))); err == nil {
		t.Fatal("expected over-limit error")
	}
	if err := ValidatePublish("爆款貼文"); err != nil {
		t.Fatalf("unexpected error: %v", err)
	}
}

func TestPublishBand(t *testing.T) {
	cases := []struct {
		len  int
		want LengthBand
	}{
		{0, BandEmpty},
		{50, BandTooShort},
		{120, BandSweet},
		{250, BandLong},
		{450, BandOverSoft},
		{501, BandOverHard},
	}
	for _, c := range cases {
		text := ""
		for range c.len {
			text += "字"
		}
		if got := PublishBand(text); got != c.want {
			t.Fatalf("len %d: got %s want %s", c.len, got, c.want)
		}
	}
}
