// // 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, "

text

") doc.lines = [.link(URL(string: "gemini://example.com/")!, text: nil)] let noText = GeminiHTMLRenderer().renderDocumentToHTML(doc) XCTAssertEqual(noText, "

gemini://example.com/

") } 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, "

test

") } 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, "

One

Two

") } func testDisableHeadingIDs() { doc.lines = [ .heading("One", level: .h1), .heading("Two", level: .h2), ] let renderer = GeminiHTMLRenderer() renderer.addHeadingLineIDs = false let html = renderer.renderDocumentToHTML(doc) XCTAssertEqual(html, "

One

Two

") } func testUnorderedList() { doc.lines = [ .text("before"), .unorderedListItem("a"), .unorderedListItem("b"), .unorderedListItem("c"), .text("after"), ] let html = GeminiHTMLRenderer().renderDocumentToHTML(doc) XCTAssertEqual(html, "

before

after

") } func testQuote() { doc.lines = [ .quote("quoted") ] let html = GeminiHTMLRenderer().renderDocumentToHTML(doc) XCTAssertEqual(html, "
quoted
") } }