102 lines
3.2 KiB
Swift
102 lines
3.2 KiB
Swift
//
|
|
// 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("<b>hello</b>")]
|
|
let html = GeminiHTMLRenderer().renderDocumentToHTML(doc)
|
|
XCTAssertEqual(html, "<p><b>hello</b></p>")
|
|
}
|
|
|
|
func testParagraph() {
|
|
doc.lines = [.text("Hello, world!")]
|
|
let html = GeminiHTMLRenderer().renderDocumentToHTML(doc)
|
|
XCTAssertEqual(html, "<p>Hello, world!</p>")
|
|
}
|
|
|
|
func testLink() {
|
|
doc.lines = [.link(URL(string: "gemini://example.com/")!, text: "text")]
|
|
let html = GeminiHTMLRenderer().renderDocumentToHTML(doc)
|
|
XCTAssertEqual(html, "<p class=\"link\"><a href=\"gemini://example.com/\">text</a></p>")
|
|
|
|
doc.lines = [.link(URL(string: "gemini://example.com/")!, text: nil)]
|
|
let noText = GeminiHTMLRenderer().renderDocumentToHTML(doc)
|
|
XCTAssertEqual(noText, "<p class=\"link\"><a href=\"gemini://example.com/\">gemini://example.com/</a></p>")
|
|
}
|
|
|
|
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, "<p><a href=\"gemini://example.com/\">test</a></p>")
|
|
}
|
|
|
|
func testPreformatting() {
|
|
doc.lines = [
|
|
.preformattedToggle(alt: nil),
|
|
.preformattedText("foo"),
|
|
.preformattedText("* bar"),
|
|
.preformattedToggle(alt: nil),
|
|
]
|
|
let html = GeminiHTMLRenderer().renderDocumentToHTML(doc)
|
|
XCTAssertEqual(html, "<pre>foo\n* bar\n</pre>")
|
|
}
|
|
|
|
func testHeading() {
|
|
doc.lines = [
|
|
.heading("One", level: .h1),
|
|
.heading("Two", level: .h2),
|
|
]
|
|
let html = GeminiHTMLRenderer().renderDocumentToHTML(doc)
|
|
XCTAssertEqual(html, "<h1 id=\"l0\">One</h1><h2 id=\"l1\">Two</h2>")
|
|
}
|
|
|
|
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, "<h1>One</h1><h2>Two</h2>")
|
|
}
|
|
|
|
func testUnorderedList() {
|
|
doc.lines = [
|
|
.text("before"),
|
|
.unorderedListItem("a"),
|
|
.unorderedListItem("b"),
|
|
.unorderedListItem("c"),
|
|
.text("after"),
|
|
]
|
|
let html = GeminiHTMLRenderer().renderDocumentToHTML(doc)
|
|
XCTAssertEqual(html, "<p>before</p><ul><li>a</li><li>b</li><li>c</li></ul><p>after</p>")
|
|
}
|
|
|
|
func testQuote() {
|
|
doc.lines = [
|
|
.quote("quoted")
|
|
]
|
|
let html = GeminiHTMLRenderer().renderDocumentToHTML(doc)
|
|
XCTAssertEqual(html, "<blockquote>quoted</blockquote>")
|
|
}
|
|
|
|
}
|