HutchTests/OrgNativeRenderingTests.swift

v3.12.3
hutch/HutchTests/OrgNativeRenderingTests.swift history · blame · raw

29 lines · 1108 bytes

 1import Foundation
 2import OrgSwiftUI
 3import Testing
 4@testable import Hutch
 5
 6/// `SyntaxHighlighter` as an `OrgCodeStyler` — the native counterpart to the HTML path.
 7/// The renderer it feeds is covered by org-swift's own tests.
 8@MainActor
 9struct OrgNativeRenderingTests {
10
11    @Test
12    func syntaxHighlighterStylesCodeNatively() throws {
13        let highlighter = SyntaxHighlighter(theme: .dark)
14        let styled = try #require(
15            highlighter.highlighted(code: "let x = 1\nprint(x)", language: "swift")
16        )
17
18        #expect(String(styled.characters) == "let x = 1\nprint(x)")
19
20        // Highlighting means more than one color across the run, in a monospaced font that
21        // scales with Dynamic Type — which the fixed-size HTML never did.
22        let colors = Set(styled.runs.compactMap { $0.foregroundColor })
23        #expect(colors.count > 1)
24        #expect(styled.runs.allSatisfy { $0.font != nil })
25
26        // An unknown language falls back to plain rather than mis-highlighting.
27        #expect(highlighter.highlighted(code: "+++", language: "notalanguage") == nil)
28    }
29}