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

Function TestAttachAssetsToMarkdown

internal/attachments/references_test.go:25–863  ·  view source on GitHub ↗
(t *testing.T)

Source from the content-addressed store, hash-verified

23}
24
25func TestAttachAssetsToMarkdown(t *testing.T) {
26 absPNG, err := filepath.Abs("./login.png")
27 require.NoError(t, err)
28
29 // The rows with a markdownDir read as though the markdown came from
30 // docs/plan.md, with the diagram beside it.
31 docsPNG := attachmentArg{Path: "docs/diagram.png", URL: pngURL, Alt: "diagram"}
32 workingDirPNG := attachmentArg{Path: "./diagram.png", URL: "https://example.com/working-dir", Alt: "diagram"}
33
34 tests := []struct {
35 name string
36 markdown string
37 markdownDir string
38 attachmentArgs []attachmentArg
39 wantMarkdown string
40 wantToAppend []attachmentArg
41 wantErr string
42 }{
43 {
44 name: "image embed on its own line keeps its markdown",
45 markdown: "Before\n\n![the login screen](./login.png)\n\nAfter",
46 attachmentArgs: []attachmentArg{pngArg()},
47 wantMarkdown: "Before\n\n![the login screen](" + pngURL + ")\n\nAfter",
48 },
49 {
50 name: "image embed inline keeps its markdown",
51 markdown: "The screen ![the login screen](./login.png) looks wrong.",
52 attachmentArgs: []attachmentArg{pngArg()},
53 wantMarkdown: "The screen ![the login screen](" + pngURL + ") looks wrong.",
54 },
55 {
56 name: "image link stays a link",
57 markdown: "See [the screenshot](./login.png) for detail.",
58 attachmentArgs: []attachmentArg{pngArg()},
59 wantMarkdown: "See [the screenshot](" + pngURL + ") for detail.",
60 },
61 {
62 name: "image never referenced is reported for appending",
63 markdown: "No references here.",
64 attachmentArgs: []attachmentArg{pngArg()},
65 wantMarkdown: "No references here.",
66 wantToAppend: []attachmentArg{pngArg()},
67 },
68
69 {
70 name: "video embed alone in its own paragraph becomes a bare url",
71 markdown: "Watch:\n\n![screen recording](./repro.mp4)\n\nEnd",
72 attachmentArgs: []attachmentArg{mp4Arg()},
73 wantMarkdown: "Watch:\n\n" + mp4URL + "\n\nEnd",
74 },
75 {
76 name: "video embed alone in a paragraph padded with spaces becomes a bare url",
77 markdown: " ![screen recording](./repro.mp4) ",
78 attachmentArgs: []attachmentArg{mp4Arg()},
79 wantMarkdown: " " + mp4URL + " ",
80 },
81 {
82 name: "video embed inline degrades to a link",

Callers

nothing calls this directly

Calls 6

pngArgFunction · 0.85
mp4ArgFunction · 0.85
newAttachableMarkdownFunction · 0.85
attachAssetsToMarkdownFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected