package mdlist import ( "gno.land/p/nym-moultest123/md/v0" "strings" "testing" "gno.land/p/nt/uassert/v0" "gno.land/p/nt/urequire/v0" ) func TestBulletList(t *testing.T) { list := Entries{ {Title: "First", Body: "Body1", Links: []string{"[link1](url1)"}}, {Title: "Second", Body: "Body2", Links: []string{"[link2](url2)", "[link3](url3)"}}, {Title: "Third", Body: "Body3", Link: "https://example.com"}, {Title: "Fourth", Body: "Body4", Link: "https://example.com", Links: []string{"[link4](url4)", "[link5](url5)"}}, } col1 := "- **First**: *Body1* [link1](url1)" col2 := "- **Second**: *Body2* [link2](url2) [link3](url3)" col3 := "- **[Third](https://example.com)**: *Body3*" col4 := "- **[Fourth](https://example.com)**: *Body4* [link4](url4) [link5](url5)" expected := strings.Join([]string{col1, col2, col3, col4}, "\n") + "\n" uassert.Equal(t, expected, list.BulletList()) } func TestColumns(t *testing.T) { list := Entries{ {Title: "First", Body: "Body1", Links: []string{"[link1](url1)"}}, {Title: "Second", Body: "Body2", Links: []string{"[link2](url2)", "[link3](url3)"}}, {Title: "Third", Body: "Body3", Link: "https://example.com"}, {Title: "Fourth", Body: "Body4", Link: "https://example.com", Links: []string{"[link4](url4)", "[link5](url5)"}}, } col1 := "## First\nBody1\n\n[link1](url1)\n\n" col2 := "## Second\nBody2\n\n[link2](url2) [link3](url3)\n\n" col3 := "## [Third](https://example.com)\nBody3\n\n\n\n" col4 := "## [Fourth](https://example.com)\nBody4\n\n[link4](url4) [link5](url5)\n\n" expected := "\n" + col1 + "\n\n" + col2 + "\n\n" + col3 + "\n\n" + col4 + "\n\n" uassert.Equal(t, expected, list.Columns()) } func TestBulletListTruncated(t *testing.T) { list := Entries{ {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)"}}, {Title: "Short", Body: "Short body"}, } // Test truncation result := list.BulletListTruncated(10, 20) // Should contain truncated text expected := "- **Very lo...**: *Very long body th...* [link1](url1)\n- **Short**: *Short body*\n" uassert.Equal(t, expected, result) } func TestNumberedList(t *testing.T) { list := Entries{ {Title: "First", Body: "Body1"}, {Title: "Second", Body: "Body2", Link: "https://example.com"}, } expected := "1. **First**: *Body1*\n2. **[Second](https://example.com)**: *Body2*\n" uassert.Equal(t, expected, list.NumberedList()) } func TestParagraphs(t *testing.T) { list := Entries{ {Title: "First", Body: "Body1", Links: []string{"[link1](url1)"}}, {Title: "Second", Body: "Body2", Link: "https://example.com"}, } expected := "**First**. Body1 [link1](url1)\n\n**[Second](https://example.com)**. Body2" uassert.Equal(t, expected, list.Paragraphs()) } func TestTruncateText(t *testing.T) { long := "abcd\nefghijklmnopqrs\ntuvwxyz01\n23456789" short := "short" urequire.Equal(t, "abcd ef...", truncateText(long, 10, false)) urequire.Equal(t, short, truncateText(short, 10, false)) urequire.Equal(t, "abcd\nef...", truncateText(long, 10, true)) urequire.Equal(t, "short", truncateText(short, 10, true)) } func TestEntriesRendering(t *testing.T) { list := Entries{ Entry{ Title: "Entry 1", Body: "Body 1", Links: []string{ md.Link("Example", "https://example.com"), }, }, Entry{ Title: "Entry 2", Body: "Body 2", }, Entry{ Title: "Entry 3", Body: "Body 3", Links: []string{ md.Link("Example1", "https://example.com/1"), md.Link("Example2", "https://example.com/2"), }, }, Entry{ Title: "Entry 4", Body: "Body 4", Link: "https://example.com/4", }, Entry{ Title: "Entry 5", Body: "Body 5", Link: "https://example.com/5", Links: []string{ md.Link("Example3", "https://example.com/3"), }, }, } uassert.Equal(t, ` ## Entry 1 Body 1 [Example](https://example.com) ## Entry 2 Body 2 ## Entry 3 Body 3 [Example1](https://example.com/1) [Example2](https://example.com/2) ## [Entry 4](https://example.com/4) Body 4 ## [Entry 5](https://example.com/5) Body 5 [Example3](https://example.com/3) `, list.Columns()) uassert.Equal(t, `- **Entry 1**: *Body 1* [Example](https://example.com) - **Entry 2**: *Body 2* - **Entry 3**: *Body 3* [Example1](https://example.com/1) [Example2](https://example.com/2) - **[Entry 4](https://example.com/4)**: *Body 4* - **[Entry 5](https://example.com/5)**: *Body 5* [Example3](https://example.com/3) `, list.BulletList()) uassert.Equal(t, `1. **Entry 1**: *Body 1* [Example](https://example.com) 2. **Entry 2**: *Body 2* 3. **Entry 3**: *Body 3* [Example1](https://example.com/1) [Example2](https://example.com/2) 4. **[Entry 4](https://example.com/4)**: *Body 4* 5. **[Entry 5](https://example.com/5)**: *Body 5* [Example3](https://example.com/3) `, list.NumberedList()) uassert.Equal(t, `**Entry 1**. Body 1 [Example](https://example.com) **Entry 2**. Body 2 **Entry 3**. Body 3 [Example1](https://example.com/1) [Example2](https://example.com/2) **[Entry 4](https://example.com/4)**. Body 4 **[Entry 5](https://example.com/5)**. Body 5 [Example3](https://example.com/3)`, list.Paragraphs()) }