57 lines
2.1 KiB
Swift
57 lines
2.1 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
|
|
""")
|
|
}
|
|
|
|
}
|