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

Function TestIsSingleImage

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

Source from the content-addressed store, hash-verified

966}
967
968func TestIsSingleImage(t *testing.T) {
969 const url = "https://example.invalid/probe"
970
971 tests := []struct {
972 name string
973 markdown string
974 want bool
975 }{
976 {
977 name: "one image pointing where it should",
978 markdown: "![a caption](" + url + ")",
979 want: true,
980 },
981 {
982 name: "empty alt text",
983 markdown: "![](" + url + ")",
984 want: true,
985 },
986 {
987 name: "brackets that stay inside because they are escaped",
988 markdown: `![a \[bracketed\] caption](` + url + `)`,
989 want: true,
990 },
991 {
992 name: "alt text that closes the image early takes the destination",
993 markdown: "![](https://evil.example.com/x.png)](" + url + ")",
994 want: false,
995 },
996 {
997 name: "alt text that adds a second image",
998 markdown: "![a](" + url + ")![b](" + url + ")",
999 want: false,
1000 },
1001 {
1002 name: "alt text that leaves trailing prose outside the image",
1003 markdown: "![a](" + url + ") and more",
1004 want: false,
1005 },
1006 {
1007 name: "alt text that opens a second paragraph",
1008 markdown: "![a](" + url + ")\n\nsecond",
1009 want: false,
1010 },
1011 {
1012 name: "an image pointing somewhere else",
1013 markdown: "![a](https://evil.example.com/x.png)",
1014 want: false,
1015 },
1016 {
1017 name: "no image at all",
1018 markdown: "just prose",
1019 want: false,
1020 },
1021 {
1022 name: "nothing",
1023 markdown: "",
1024 want: false,
1025 },

Callers

nothing calls this directly

Calls 3

isSingleImageFunction · 0.85
EqualMethod · 0.80
RunMethod · 0.65

Tested by

no test coverage detected