diff options
| author | Christian Cleberg <[email protected]> | 2026-04-15 16:07:09 -0500 |
|---|---|---|
| committer | Christian Cleberg <[email protected]> | 2026-04-15 16:07:09 -0500 |
| commit | 7d5ca0607c091f76aa29cd6fa8c76cfeb1e02ac8 (patch) | |
| tree | eef9213c86b32d3b1b295bf503577fa362d6f1fc /HutchTests/ReadmeViewTests.swift | |
| parent | 06c36c4352f47655cb39a5042a7e5fd475c118e1 (diff) | |
| download | hutch-7d5ca0607c091f76aa29cd6fa8c76cfeb1e02ac8.tar.gz hutch-7d5ca0607c091f76aa29cd6fa8c76cfeb1e02ac8.tar.bz2 hutch-7d5ca0607c091f76aa29cd6fa8c76cfeb1e02ac8.zip | |
fix: fixes dead relative links in md/org with a new single-file viewer when tapped
Fixes: https://todo.sr.ht/~ccleberg/hutch/63
Diffstat (limited to 'HutchTests/ReadmeViewTests.swift')
| -rw-r--r-- | HutchTests/ReadmeViewTests.swift | 101 |
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("") @@ -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") + } +} |
