81 lines
2.9 KiB
Swift
81 lines
2.9 KiB
Swift
//
|
|
// DocumentTests.swift
|
|
// GeminiFormatTests
|
|
//
|
|
// Created by Shadowfacts on 7/12/20.
|
|
//
|
|
|
|
import XCTest
|
|
@testable import GeminiFormat
|
|
|
|
class DocumentTests: XCTestCase {
|
|
|
|
func testLineText() {
|
|
XCTAssertEqual(Document.Line.text("some text").geminiText(), "some text")
|
|
XCTAssertEqual(Document.Line.link(URL(string: "gemini://example.com/foo?bar")!, text: "some link").geminiText(), "=> gemini://example.com/foo?bar some link")
|
|
XCTAssertEqual(Document.Line.link(URL(string: "gemini://example.com/foo?bar")!, text: nil).geminiText(), "=> gemini://example.com/foo?bar")
|
|
XCTAssertEqual(Document.Line.preformattedToggle(alt: "blah").geminiText(), "```blah")
|
|
XCTAssertEqual(Document.Line.preformattedToggle(alt: nil).geminiText(), "```")
|
|
XCTAssertEqual(Document.Line.preformattedText("test").geminiText(), "test")
|
|
XCTAssertEqual(Document.Line.heading("one", level: .h1).geminiText(), "# one")
|
|
XCTAssertEqual(Document.Line.heading("two", level: .h2).geminiText(), "## two")
|
|
XCTAssertEqual(Document.Line.heading("three", level: .h3).geminiText(), "### three")
|
|
XCTAssertEqual(Document.Line.unorderedListItem("list item").geminiText(), "* list item")
|
|
XCTAssertEqual(Document.Line.quote("quoted").geminiText(), "> quoted")
|
|
}
|
|
|
|
func testDocumentText() {
|
|
let doc = Document(url: URL(string: "gemini://example.com")!, lines: [
|
|
.text("text"),
|
|
.link(URL(string: "gemini://example.com/")!, text: "a link"),
|
|
.link(URL(string: "gemini://example.com/foo?bar")!, text: nil),
|
|
.preformattedToggle(alt: "blah"),
|
|
.preformattedText("test"),
|
|
.preformattedToggle(alt: nil),
|
|
.heading("one", level: .h1),
|
|
.heading("two", level: .h2),
|
|
.heading("three", level: .h3),
|
|
.unorderedListItem("list item"),
|
|
.quote("quoted"),
|
|
])
|
|
XCTAssertEqual(doc.toGeminiText(), """
|
|
text
|
|
=> gemini://example.com/ a link
|
|
=> gemini://example.com/foo?bar
|
|
```blah
|
|
test
|
|
```
|
|
# one
|
|
## two
|
|
### three
|
|
* list item
|
|
> quoted
|
|
""")
|
|
}
|
|
|
|
func testGetTitle() {
|
|
let h1 = Document(url: URL(string: "gemini://example.com/")!, lines: [
|
|
.heading("Test", level: .h1)
|
|
])
|
|
XCTAssertEqual(h1.title, "Test")
|
|
|
|
let h2 = Document(url: URL(string: "gemini://example.com/")!, lines: [
|
|
.heading("Test", level: .h2)
|
|
])
|
|
XCTAssertEqual(h2.title, "Test")
|
|
|
|
let h3 = Document(url: URL(string: "gemini://example.com/")!, lines: [
|
|
.heading("Test", level: .h3)
|
|
])
|
|
XCTAssertEqual(h3.title, "Test")
|
|
|
|
let multiple = Document(url: URL(string: "gemini://example.com/")!, lines: [
|
|
.heading("Two", level: .h2),
|
|
.heading("One", level: .h1),
|
|
.heading("Three", level: .h3),
|
|
])
|
|
XCTAssertEqual(multiple.title, "Two")
|
|
}
|
|
|
|
}
|