diff --git a/GeminiRendererTests/GeminiHTMLRendererTests.swift b/GeminiRendererTests/GeminiHTMLRendererTests.swift new file mode 100644 index 0000000..42be4e7 --- /dev/null +++ b/GeminiRendererTests/GeminiHTMLRendererTests.swift @@ -0,0 +1,101 @@ +// +// GeminiHTMLRendererTests.swift +// GeminiRendererTests +// +// Created by Shadowfacts on 10/1/21. +// + +import XCTest +import GeminiFormat +@testable import GeminiRenderer + +class GeminiHTMLRendererTests: XCTestCase { + + private var doc: Document! + + override func setUp() { + doc = Document(url: URL(string: "gemini://example.com/")!) + } + + func testEscapeToEntities() { + doc.lines = [.text("hello")] + let html = GeminiHTMLRenderer().renderDocumentToHTML(doc) + XCTAssertEqual(html, "
<b>hello</b>
") + } + + func testParagraph() { + doc.lines = [.text("Hello, world!")] + let html = GeminiHTMLRenderer().renderDocumentToHTML(doc) + XCTAssertEqual(html, "Hello, world!
") + } + + func testLink() { + doc.lines = [.link(URL(string: "gemini://example.com/")!, text: "text")] + let html = GeminiHTMLRenderer().renderDocumentToHTML(doc) + XCTAssertEqual(html, "") + + doc.lines = [.link(URL(string: "gemini://example.com/")!, text: nil)] + let noText = GeminiHTMLRenderer().renderDocumentToHTML(doc) + XCTAssertEqual(noText, "") + } + + func testDisableLinkClass() { + doc.lines = [.link(URL(string: "gemini://example.com/")!, text: "test")] + let renderer = GeminiHTMLRenderer() + renderer.addLinkClass = false + let html = renderer.renderDocumentToHTML(doc) + XCTAssertEqual(html, "") + } + + func testPreformatting() { + doc.lines = [ + .preformattedToggle(alt: nil), + .preformattedText("foo"), + .preformattedText("* bar"), + .preformattedToggle(alt: nil), + ] + let html = GeminiHTMLRenderer().renderDocumentToHTML(doc) + XCTAssertEqual(html, "foo\n* bar\n") + } + + func testHeading() { + doc.lines = [ + .heading("One", level: .h1), + .heading("Two", level: .h2), + ] + let html = GeminiHTMLRenderer().renderDocumentToHTML(doc) + XCTAssertEqual(html, "
before
after
") + } + + func testQuote() { + doc.lines = [ + .quote("quoted") + ] + let html = GeminiHTMLRenderer().renderDocumentToHTML(doc) + XCTAssertEqual(html, "quoted") + } + +}