diff options
| author | Ruben Beltran del Rio <jj@r.bdr.sh> | 2026-06-15 14:35:36 +0200 |
|---|---|---|
| committer | Ruben Beltran del Rio <jj@r.bdr.sh> | 2026-06-16 14:47:30 +0200 |
| commit | 657aa83a5ca24dc35572c040df64a0abb85e8612 (patch) | |
| tree | fe0b6fd425d8cad9dc6a28ada4ad8600e42b367e /Tests/NorgUITests/InlineTextTests.swift | |
Initial extraction from Norganize
Diffstat (limited to 'Tests/NorgUITests/InlineTextTests.swift')
| -rw-r--r-- | Tests/NorgUITests/InlineTextTests.swift | 79 |
1 files changed, 79 insertions, 0 deletions
diff --git a/Tests/NorgUITests/InlineTextTests.swift b/Tests/NorgUITests/InlineTextTests.swift new file mode 100644 index 0000000..c2c6537 --- /dev/null +++ b/Tests/NorgUITests/InlineTextTests.swift @@ -0,0 +1,79 @@ +import NorgKit +import SwiftUI +import Testing + +@testable import NorgUI + +@Suite struct InlineTextTests { + @Test func plainSpanCarriesText() { + let attributed = AttributedString(norg: [InlineSpan(text: "hello")]) + #expect(String(attributed.characters) == "hello") + } + + @Test func multipleSpansConcatenate() { + let attributed = AttributedString(norg: [ + InlineSpan(text: "foo"), + InlineSpan(text: "bar"), + ]) + #expect(String(attributed.characters) == "foobar") + } + + @Test func verbatimUsesThemeColor() { + let attributed = AttributedString(norg: [InlineSpan(text: "x", styles: .verbatim)]) + let run = attributed.runs.first + #expect(run?.foregroundColor == NorgTheme.default.verbatimColor) + } + + @Test func spoilerAppliesForegroundAndBackground() { + let attributed = AttributedString(norg: [InlineSpan(text: "x", styles: .spoiler)]) + let run = attributed.runs.first + #expect(run?.foregroundColor == NorgTheme.default.spoilerForeground) + #expect(run?.backgroundColor == NorgTheme.default.spoilerBackground) + } + + @Test func superscriptUsesThemeOffset() { + let attributed = AttributedString(norg: [InlineSpan(text: "x", styles: .superscript)]) + #expect(attributed.runs.first?.baselineOffset == NorgTheme.default.superscriptOffset) + } + + @Test func subscriptUsesThemeOffset() { + let attributed = AttributedString(norg: [InlineSpan(text: "x", styles: .subscript)]) + #expect(attributed.runs.first?.baselineOffset == NorgTheme.default.subscriptOffset) + } + + @Test func externalLinkBecomesTappable() { + let attributed = AttributedString(norg: [ + InlineSpan(text: "site", link: InlineLink(kind: .link, target: "https://example.com")) + ]) + let run = attributed.runs.first + #expect(run?.link == URL(string: "https://example.com")) + #expect(run?.foregroundColor == NorgTheme.default.linkColor) + } + + @Test func internalLinkIsEncodedForRouting() { + let attributed = AttributedString(norg: [ + InlineSpan(text: "note", link: InlineLink(kind: .link, target: "* Some heading")) + ]) + let run = attributed.runs.first + let decoded = run?.link.flatMap(NorgLinkURL.decode) + #expect(decoded == InlineLink(kind: .link, target: "* Some heading")) + #expect(run?.foregroundColor == NorgTheme.default.linkColor) + } + + @Test func anchorIsEncodedForRouting() { + let attributed = AttributedString(norg: [ + InlineSpan(text: "ref", link: InlineLink(kind: .anchor, target: "footnote")) + ]) + let run = attributed.runs.first + let decoded = run?.link.flatMap(NorgLinkURL.decode) + #expect(decoded == InlineLink(kind: .anchor, target: "footnote")) + } + + @Test func customThemeOverridesColors() { + var theme = NorgTheme.default + theme.verbatimColor = .orange + let attributed = AttributedString( + norg: [InlineSpan(text: "x", styles: .verbatim)], theme: theme) + #expect(attributed.runs.first?.foregroundColor == .orange) + } +} |