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

Community realm. Read the code first. Community realm, deployed by its author. Read the code before you interact or send coins.

mdlist_test.gno

5.26 Kb · 175 lines
  1package mdlist
  2
  3import (
  4	"gno.land/p/nym-moultest123/md/v0"
  5	"strings"
  6	"testing"
  7
  8	"gno.land/p/nt/uassert/v0"
  9	"gno.land/p/nt/urequire/v0"
 10)
 11
 12func TestBulletList(t *testing.T) {
 13	list := Entries{
 14		{Title: "First", Body: "Body1", Links: []string{"[link1](url1)"}},
 15		{Title: "Second", Body: "Body2", Links: []string{"[link2](url2)", "[link3](url3)"}},
 16		{Title: "Third", Body: "Body3", Link: "https://example.com"},
 17		{Title: "Fourth", Body: "Body4", Link: "https://example.com", Links: []string{"[link4](url4)", "[link5](url5)"}},
 18	}
 19	col1 := "- **First**: *Body1* [link1](url1)"
 20	col2 := "- **Second**: *Body2* [link2](url2) [link3](url3)"
 21	col3 := "- **[Third](https://example.com)**: *Body3*"
 22	col4 := "- **[Fourth](https://example.com)**: *Body4* [link4](url4) [link5](url5)"
 23	expected := strings.Join([]string{col1, col2, col3, col4}, "\n") + "\n"
 24	uassert.Equal(t, expected, list.BulletList())
 25}
 26
 27func TestColumns(t *testing.T) {
 28	list := Entries{
 29		{Title: "First", Body: "Body1", Links: []string{"[link1](url1)"}},
 30		{Title: "Second", Body: "Body2", Links: []string{"[link2](url2)", "[link3](url3)"}},
 31		{Title: "Third", Body: "Body3", Link: "https://example.com"},
 32		{Title: "Fourth", Body: "Body4", Link: "https://example.com", Links: []string{"[link4](url4)", "[link5](url5)"}},
 33	}
 34	col1 := "## First\nBody1\n\n[link1](url1)\n\n"
 35	col2 := "## Second\nBody2\n\n[link2](url2) [link3](url3)\n\n"
 36	col3 := "## [Third](https://example.com)\nBody3\n\n\n\n"
 37	col4 := "## [Fourth](https://example.com)\nBody4\n\n[link4](url4) [link5](url5)\n\n"
 38	expected := "<gno-columns>\n" + col1 + "\n<gno-columns-sep>\n" + col2 + "\n<gno-columns-sep>\n" + col3 + "\n<gno-columns-sep>\n" + col4 + "\n</gno-columns>\n"
 39	uassert.Equal(t, expected, list.Columns())
 40}
 41
 42func TestBulletListTruncated(t *testing.T) {
 43	list := Entries{
 44		{Title: "Very long title that should be truncated", Body: "Very long body that should also be truncated because it is too long", Links: []string{"[link1](url1)"}},
 45		{Title: "Short", Body: "Short body"},
 46	}
 47	// Test truncation
 48	result := list.BulletListTruncated(10, 20)
 49	// Should contain truncated text
 50	expected := "- **Very lo...**: *Very long body th...* [link1](url1)\n- **Short**: *Short body*\n"
 51	uassert.Equal(t, expected, result)
 52}
 53
 54func TestNumberedList(t *testing.T) {
 55	list := Entries{
 56		{Title: "First", Body: "Body1"},
 57		{Title: "Second", Body: "Body2", Link: "https://example.com"},
 58	}
 59	expected := "1. **First**: *Body1*\n2. **[Second](https://example.com)**: *Body2*\n"
 60	uassert.Equal(t, expected, list.NumberedList())
 61}
 62
 63func TestParagraphs(t *testing.T) {
 64	list := Entries{
 65		{Title: "First", Body: "Body1", Links: []string{"[link1](url1)"}},
 66		{Title: "Second", Body: "Body2", Link: "https://example.com"},
 67	}
 68	expected := "**First**. Body1 [link1](url1)\n\n**[Second](https://example.com)**. Body2"
 69	uassert.Equal(t, expected, list.Paragraphs())
 70}
 71
 72func TestTruncateText(t *testing.T) {
 73	long := "abcd\nefghijklmnopqrs\ntuvwxyz01\n23456789"
 74	short := "short"
 75	urequire.Equal(t, "abcd ef...", truncateText(long, 10, false))
 76	urequire.Equal(t, short, truncateText(short, 10, false))
 77	urequire.Equal(t, "abcd\nef...", truncateText(long, 10, true))
 78	urequire.Equal(t, "short", truncateText(short, 10, true))
 79}
 80
 81func TestEntriesRendering(t *testing.T) {
 82	list := Entries{
 83		Entry{
 84			Title: "Entry 1",
 85			Body:  "Body 1",
 86			Links: []string{
 87				md.Link("Example", "https://example.com"),
 88			},
 89		},
 90		Entry{
 91			Title: "Entry 2",
 92			Body:  "Body 2",
 93		},
 94		Entry{
 95			Title: "Entry 3",
 96			Body:  "Body 3",
 97			Links: []string{
 98				md.Link("Example1", "https://example.com/1"),
 99				md.Link("Example2", "https://example.com/2"),
100			},
101		},
102		Entry{
103			Title: "Entry 4",
104			Body:  "Body 4",
105			Link:  "https://example.com/4",
106		},
107		Entry{
108			Title: "Entry 5",
109			Body:  "Body 5",
110			Link:  "https://example.com/5",
111			Links: []string{
112				md.Link("Example3", "https://example.com/3"),
113			},
114		},
115	}
116
117	uassert.Equal(t, `<gno-columns>
118## Entry 1
119Body 1
120
121[Example](https://example.com)
122
123
124<gno-columns-sep>
125## Entry 2
126Body 2
127
128
129
130
131<gno-columns-sep>
132## Entry 3
133Body 3
134
135[Example1](https://example.com/1) [Example2](https://example.com/2)
136
137
138<gno-columns-sep>
139## [Entry 4](https://example.com/4)
140Body 4
141
142
143
144
145<gno-columns-sep>
146## [Entry 5](https://example.com/5)
147Body 5
148
149[Example3](https://example.com/3)
150
151
152</gno-columns>
153`, list.Columns())
154	uassert.Equal(t, `- **Entry 1**: *Body 1* [Example](https://example.com)
155- **Entry 2**: *Body 2*
156- **Entry 3**: *Body 3* [Example1](https://example.com/1) [Example2](https://example.com/2)
157- **[Entry 4](https://example.com/4)**: *Body 4*
158- **[Entry 5](https://example.com/5)**: *Body 5* [Example3](https://example.com/3)
159`, list.BulletList())
160	uassert.Equal(t, `1. **Entry 1**: *Body 1* [Example](https://example.com)
1612. **Entry 2**: *Body 2*
1623. **Entry 3**: *Body 3* [Example1](https://example.com/1) [Example2](https://example.com/2)
1634. **[Entry 4](https://example.com/4)**: *Body 4*
1645. **[Entry 5](https://example.com/5)**: *Body 5* [Example3](https://example.com/3)
165`, list.NumberedList())
166	uassert.Equal(t, `**Entry 1**. Body 1 [Example](https://example.com)
167
168**Entry 2**. Body 2
169
170**Entry 3**. Body 3 [Example1](https://example.com/1) [Example2](https://example.com/2)
171
172**[Entry 4](https://example.com/4)**. Body 4
173
174**[Entry 5](https://example.com/5)**. Body 5 [Example3](https://example.com/3)`, list.Paragraphs())
175}