MCPcopy Create free account
hub / github.com/cli/cli / TestAssetMarkdown

Function TestAssetMarkdown

internal/attachments/userasset_test.go:271–331  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

269}
270
271func TestAssetMarkdown(t *testing.T) {
272 tests := []struct {
273 name string
274 contentType string
275 alt string
276 want string
277 }{
278 {
279 name: "image",
280 contentType: "image/png",
281 alt: "The login error state",
282 want: "![The login error state](https://example.com/assets/1)",
283 },
284 {
285 name: "image with empty alt text",
286 contentType: "image/png",
287 want: "![](https://example.com/assets/1)",
288 },
289 {
290 name: "video renders as a bare URL so it plays",
291 contentType: "video/mp4",
292 want: "https://example.com/assets/1",
293 },
294 {
295 // A bare URL is the only form that plays.
296 name: "a video alt does not reach the embed",
297 contentType: "video/mp4",
298 alt: "repro.mp4",
299 want: "https://example.com/assets/1",
300 },
301 {
302 name: "alt text cannot close the image early",
303 contentType: "image/png",
304 alt: "![x](https://evil.example.com/x.png)",
305 want: `![!\[x\](https://evil.example.com/x.png)](https://example.com/assets/1)`,
306 },
307 {
308 name: "backslashes are escaped",
309 contentType: "image/png",
310 alt: `a\b`,
311 want: `![a\\b](https://example.com/assets/1)`,
312 },
313 {
314 name: "newlines cannot break out of the image",
315 contentType: "image/png",
316 alt: "first\nsecond\r\nthird",
317 want: "![first second third](https://example.com/assets/1)",
318 },
319 }
320
321 for _, tt := range tests {
322 t.Run(tt.name, func(t *testing.T) {
323 var a UserAsset = &imageAsset{asset{contentType: tt.contentType, alt: tt.alt}}
324 if strings.HasPrefix(tt.contentType, "video/") {
325 a = &videoAsset{asset{contentType: tt.contentType, alt: tt.alt}}
326 }
327
328 assert.Equal(t, tt.want, a.markdown("https://example.com/assets/1"))

Callers

nothing calls this directly

Calls 3

markdownMethod · 0.95
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected