thread-master/backend/internal/library/threadspost/format_test.go

49 lines
1.6 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package threadspost
import "testing"
func TestFormatDraftTextPreservesPunctuationAndLineBreaks(t *testing.T) {
raw := "我最近迷上自己做早餐耶!\n以前都隨便買個麵包、三明治趕著出門。\n有沒有人也跟我一樣"
want := "我最近迷上自己做早餐耶!\n以前都隨便買個麵包、三明治趕著出門。\n有沒有人也跟我一樣"
got := FormatDraftText(raw)
if got != want {
t.Fatalf("FormatDraftText() = %q, want %q", got, want)
}
}
func TestFormatDraftTextKeepsSingleParagraph(t *testing.T) {
raw := "第一句很好。第二句也不錯!第三句收尾?"
want := "第一句很好。第二句也不錯!第三句收尾?"
got := FormatDraftText(raw)
if got != want {
t.Fatalf("FormatDraftText() = %q, want %q", got, want)
}
}
func TestFormatDraftTextCollapsesExcessBlankLines(t *testing.T) {
raw := "第一段\n\n\n第二段"
want := "第一段\n\n第二段"
got := FormatDraftText(raw)
if got != want {
t.Fatalf("FormatDraftText() = %q, want %q", got, want)
}
}
func TestFormatDraftTextPreservesEmoji(t *testing.T) {
raw := "廚房像打完仗一樣 😂\n但看到成果就值得了"
want := "廚房像打完仗一樣 😂\n但看到成果就值得了"
got := FormatDraftText(raw)
if got != want {
t.Fatalf("FormatDraftText() = %q, want %q", got, want)
}
}
func TestFormatDraftTextPreservesHashtag(t *testing.T) {
raw := "今天心情不錯\n#早餐日記"
want := "今天心情不錯\n#早餐日記"
got := FormatDraftText(raw)
if got != want {
t.Fatalf("FormatDraftText() = %q, want %q", got, want)
}
}