summaryrefslogtreecommitdiff
path: root/HutchTests/ReadmeViewTests.swift
diff options
context:
space:
mode:
Diffstat (limited to 'HutchTests/ReadmeViewTests.swift')
-rw-r--r--HutchTests/ReadmeViewTests.swift101
1 files changed, 101 insertions, 0 deletions
diff --git a/HutchTests/ReadmeViewTests.swift b/HutchTests/ReadmeViewTests.swift
index f338525..3b9d80b 100644
--- a/HutchTests/ReadmeViewTests.swift
+++ b/HutchTests/ReadmeViewTests.swift
@@ -104,6 +104,44 @@ struct MarkdownRenderingTests {
}
@Test
+ func markdownRelativeLinkWithoutResolverDropped() {
+ let html = markdownToHTML("[LICENSE](LICENSE)")
+
+ #expect(!html.contains("href="))
+ #expect(html.contains("LICENSE"))
+ }
+
+ @Test
+ func markdownRelativeLinkWithResolverRendersAnchor() {
+ let html = markdownToHTML(
+ "[LICENSE](LICENSE)",
+ linkURLResolver: { source in
+ source == "LICENSE" ? "https://git.sr.ht/~ccleberg/Hutch/blob/HEAD/LICENSE" : nil
+ }
+ )
+
+ #expect(html.contains(#"href="https://git.sr.ht/~ccleberg/Hutch/blob/HEAD/LICENSE""#))
+ #expect(html.contains(">LICENSE</a>"))
+ }
+
+ @Test
+ func markdownFragmentLinkWithResolverPreservesFragment() {
+ let html = markdownToHTML(
+ "[section](#install)",
+ linkURLResolver: { source in
+ resolveRepositoryLinkURL(
+ source,
+ owner: "~ccleberg",
+ repositoryName: "Hutch",
+ readmePath: "README.md"
+ )
+ }
+ )
+
+ #expect(html.contains("href=\"#install\""))
+ }
+
+ @Test
func markdownImageRenders() {
let html = markdownToHTML("![logo](https://example.com/logo.png)")
@@ -349,3 +387,66 @@ struct RepositoryAssetURLTests {
#expect(url == "https://git.sr.ht/~ccleberg/Hutch/blob/HEAD/images/My%20Logo.png")
}
}
+
+struct RepositoryLinkURLTests {
+
+ @Test
+ func repositoryLinkURLResolvesRelativePath() {
+ let url = resolveRepositoryLinkURL(
+ "LICENSE",
+ owner: "~ccleberg",
+ repositoryName: "Hutch",
+ readmePath: "README.md"
+ )
+
+ #expect(url == "https://git.sr.ht/~ccleberg/Hutch/blob/HEAD/LICENSE")
+ }
+
+ @Test
+ func repositoryLinkURLPassesThroughAbsoluteURL() {
+ let url = resolveRepositoryLinkURL(
+ "https://example.com/page",
+ owner: "~ccleberg",
+ repositoryName: "Hutch",
+ readmePath: "README.md"
+ )
+
+ #expect(url == "https://example.com/page")
+ }
+
+ @Test
+ func repositoryLinkURLPassesThroughFragment() {
+ let url = resolveRepositoryLinkURL(
+ "#install",
+ owner: "~ccleberg",
+ repositoryName: "Hutch",
+ readmePath: "README.md"
+ )
+
+ #expect(url == "#install")
+ }
+
+ @Test
+ func repositoryLinkURLPassesThroughMailto() {
+ let url = resolveRepositoryLinkURL(
+ "mailto:[email protected]",
+ owner: "~ccleberg",
+ repositoryName: "Hutch",
+ readmePath: "README.md"
+ )
+
+ #expect(url == "mailto:[email protected]")
+ }
+
+ @Test
+ func repositoryLinkURLResolvesSubdirectoryRelativePath() {
+ let url = resolveRepositoryLinkURL(
+ "docs/SECURITY.md",
+ owner: "~ccleberg",
+ repositoryName: "Hutch",
+ readmePath: "README.md"
+ )
+
+ #expect(url == "https://git.sr.ht/~ccleberg/Hutch/blob/HEAD/docs/SECURITY.md")
+ }
+}