diff options
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) + } +} |