Monorepo for Tangled
at master 52 lines 2.2 kB view raw
1package extension_test 2 3import ( 4 "bytes" 5 "testing" 6 7 "tangled.org/core/appview/pages/markup" 8) 9 10func TestTangledLinkExtension_Rendering(t *testing.T) { 11 tests := []struct { 12 name string 13 markdown string 14 expected string 15 }{ 16 { 17 name: "renders simple commit link from commonmark autolink", 18 markdown: "This is a commit: <https://tangled.org/alice.tngl.sh/cool-repo/commit/cde4705021a07e3cb11322fb9ef78a6c786b41c0>", 19 expected: `<p>This is a commit: <a href="https://tangled.org/alice.tngl.sh/cool-repo/commit/cde4705021a07e3cb11322fb9ef78a6c786b41c0"><code>cde47050</code></a></p>`, 20 }, 21 { 22 name: "renders simple commit link from gfm autolink", 23 markdown: "This is a commit: https://tangled.org/alice.tngl.sh/cool-repo/commit/cde4705021a07e3cb11322fb9ef78a6c786b41c0", 24 expected: `<p>This is a commit: <a href="https://tangled.org/alice.tngl.sh/cool-repo/commit/cde4705021a07e3cb11322fb9ef78a6c786b41c0"><code>cde47050</code></a></p>`, 25 }, 26 { 27 name: "skip non-autolink links", 28 markdown: "This is a commit: [a commit](https://tangled.org/alice.tngl.sh/cool-repo/commit/cde4705021a07e3cb11322fb9ef78a6c786b41c0)", 29 expected: `<p>This is a commit: <a href="https://tangled.org/alice.tngl.sh/cool-repo/commit/cde4705021a07e3cb11322fb9ef78a6c786b41c0">a commit</a></p>`, 30 }, 31 { 32 name: "skip non-autolink links with content same as dest", 33 markdown: "This is a commit: [https://tangled.org/alice.tngl.sh/cool-repo/commit/cde4705021a07e3cb11322fb9ef78a6c786b41c0](https://tangled.org/alice.tngl.sh/cool-repo/commit/cde4705021a07e3cb11322fb9ef78a6c786b41c0)", 34 expected: `<p>This is a commit: <a href="https://tangled.org/alice.tngl.sh/cool-repo/commit/cde4705021a07e3cb11322fb9ef78a6c786b41c0">https://tangled.org/alice.tngl.sh/cool-repo/commit/cde4705021a07e3cb11322fb9ef78a6c786b41c0</a></p>`, 35 }, 36 } 37 for _, tt := range tests { 38 t.Run(tt.name, func(t *testing.T) { 39 md := markup.NewMarkdown("tangled.org") 40 41 var buf bytes.Buffer 42 if err := md.Convert([]byte(tt.markdown), &buf); err != nil { 43 t.Fatalf("failed to convert markdown: %v", err) 44 } 45 46 result := buf.String() 47 if result != tt.expected+"\n" { 48 t.Errorf("expected:\n%s\ngot:\n%s", tt.expected, result) 49 } 50 }) 51 } 52}