package im import ( "testing" "github.com/stretchr/testify/assert" ) func TestStripIMCitationTags(t *testing.T) { tests := []struct { name string in string want string }{ {"no tags", "hello world", "hello world"}, {"kb tag", `text more`, "text more"}, {"web tag", `see here`, "see here"}, {"multiple", `text`, "text"}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { assert.Equal(t, tt.want, stripIMCitationTags(tt.in)) }) } } func TestStripImageXMLTags(t *testing.T) { tests := []struct { name string in string want string }{ { "with image_original", ` ![alt](local://1/img.png) a cat `, "![alt](local://1/img.png)", }, { "without image_original", ` a cat `, "", }, { "no image tags", "just plain text ![img](http://example.com/img.png)", "just plain text ![img](http://example.com/img.png)", }, { "mixed content", `before ![a](b) after`, "before ![a](b) after", }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { assert.Equal(t, tt.want, stripImageXMLTags(tt.in)) }) } } func TestFindIncompleteStorageURL(t *testing.T) { tests := []struct { name string in string want int // expected return; -1 means no match expected }{ { "complete URL terminated by )", "![img](local://1/abc/img.png)", // The URL `local://1/abc/img.png` ends with `)` which is a terminator, // but the regex [^\s)\]>"]* matches up to `)` — the `)` is NOT included. // So the URL portion is `local://1/abc/img.png` and `)` terminates it. // The match does NOT reach end of string → should return -1. -1, }, { "complete URL terminated by space", "text local://1/abc/img.png more text", -1, }, { "truncated URL at end", "text ![img](local://1/abc/im", 12, // starts at `l` in `local://` }, { "just scheme at end", "text minio://", 5, }, { "no storage URL", "just plain text http://example.com", -1, }, { "URL at very end", "local://1/img.png", 0, }, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) { got := findIncompleteStorageURL(tt.in) assert.Equal(t, tt.want, got, "findIncompleteStorageURL(%q)", tt.in) }) } } func TestFindIncompleteXMLTag(t *testing.T) { tests := []struct { name string in string want int }{ { "complete tag", `text more`, -1, }, { "incomplete kb tag", `text ![alt](local://1/`, -1, // the tag itself is complete (has >), the content is truncated }, { "incomplete opening image_original", `text