Files
helder/Tests/HelderCoreTests/Markdown/MarkdownInlineParserTests.swift
T

35 lines
1.3 KiB
Swift

@testable import HelderCore
import Testing
@Suite struct MarkdownInlineParserTests {
@Test("a link destination splits into URL and optional title", arguments: [
("https://x.com", "https://x.com", nil),
("https://x.com \"Home\"", "https://x.com", "Home"),
("<a b.png> 'T'", "a b.png", "T"),
("x.png (Paren)", "x.png", "Paren"),
(" spaced ", "spaced", nil),
] as [(String, String, String?)])
func destination(raw: String, url: String, title: String?) {
let parsed = MarkdownInlineParser.destination(Substring(raw))
#expect(parsed.url == url)
#expect(parsed.title == title)
}
@Test("alt text flattens nested inline nodes")
func plainText() {
let nodes: [MarkdownInline] = [.text("a "), .strong([.code("b")]), .link(text: [.text(" c")], url: "#", title: nil)]
#expect(MarkdownInlineParser.plainText(nodes) == "a b c")
}
@Test("placeholder look-alikes in the source stay literal text")
func placeholderLookAlike() {
let text = "x \u{E000}99\u{E001} y"
#expect(MarkdownInlineParser.parse(text, baseDir: "") == [.text(text)])
}
@Test("unmatched markers stay literal")
func unmatchedMarkers() {
#expect(MarkdownInlineParser.parse("a ** b ` c [d](", baseDir: "") == [.text("a ** b ` c [d](")])
}
}