package twitter import ( "strings" "testing" ) func TestTweetLength(t *testing.T) { cases := []struct { content, url string want int }{ {"hello", "", 5}, {"hello", "https://example.com/a/very/long/path/that/x/shortens", 5 + 2 + 23}, {"café — “quoted”", "", 15}, {"🚀", "", 2}, {"日本", "", 4}, } for _, c := range cases { if got := TweetLength(c.content, c.url); got != c.want { t.Errorf("TweetLength(%q, %q) = %d, want %d", c.content, c.url, got, c.want) } } } func TestReservedLimitFits(t *testing.T) { url := "https://x.com/someone/status/123" limit := 280 - URLReserve(url) if got := TweetLength(strings.Repeat("a", limit), url); got != 280 { t.Errorf("post at reserved limit counts as %d, want 280", got) } }