Skip to content Search Apps Documentation Source Content Run Reset Eval Playground File Folder Download Copy Actions State String Boolean Number Struct Map Slice Pointer Function Closure Reference Nil Package Type Interface Unknown

post_test.gno

1.50 Kb · 44 lines
 1package boards_test
 2
 3import (
 4	"strings"
 5	"testing"
 6
 7	"gno.land/p/nt/urequire/v0"
 8
 9	"gno.land/p/gnoland/boards/v0"
10)
11
12func TestPostSummary(t *testing.T) {
13	post := &boards.Post{ID: 1, Body: strings.Repeat("X", 900)}
14	summary := post.Summary()
15	urequire.True(t, strings.HasSuffix(summary, "..."), "expect dotted suffix")
16	urequire.True(t, len(summary) == 80, "expect summary length to match")
17}
18
19func TestIsThread(t *testing.T) {
20	post := &boards.Post{ID: 1, ThreadID: 1} // IDs match
21	urequire.True(t, boards.IsThread(post), "expect post to be a thread")
22	urequire.False(t, boards.IsThread(nil), "expect nil not to be a thread")
23
24	post = &boards.Post{ID: 2, ThreadID: 1} // IDs doesn't match
25	urequire.False(t, boards.IsThread(post), "expect post not to be a thread")
26}
27
28func TestIsRepost(t *testing.T) {
29	post := &boards.Post{ID: 1, OriginalBoardID: 1} // Original board ID available
30	urequire.True(t, boards.IsRepost(post), "expect post to be a repost")
31	urequire.False(t, boards.IsRepost(nil), "expect nil not to be a repost")
32
33	post = &boards.Post{ID: 1} // Original board ID not available
34	urequire.False(t, boards.IsRepost(post), "expect post not to be a repost")
35}
36
37func TestSummaryOf(t *testing.T) {
38	summary := boards.SummaryOf(strings.Repeat("X", 90), 80)
39	urequire.True(t, strings.HasSuffix(summary, "..."), "expect dotted suffix")
40	urequire.True(t, len(summary) == 80, "expect summary length to match")
41
42	summary = boards.SummaryOf(strings.Repeat(" ", 90), 80)
43	urequire.Empty(t, summary, "expect summary to be empty")
44}