From 95dbb17779226294f9412f5f47d637c9c0c2ed3b Mon Sep 17 00:00:00 2001 From: Shadowfacts Date: Sun, 12 Jul 2020 23:23:37 -0400 Subject: [PATCH] Add complex Gemini format parse test --- GeminiFormatTests/GeminiFormatTests.swift | 100 +++++++++++++++++++++- 1 file changed, 98 insertions(+), 2 deletions(-) diff --git a/GeminiFormatTests/GeminiFormatTests.swift b/GeminiFormatTests/GeminiFormatTests.swift index 0627592..ea99614 100644 --- a/GeminiFormatTests/GeminiFormatTests.swift +++ b/GeminiFormatTests/GeminiFormatTests.swift @@ -10,9 +10,11 @@ import XCTest class GeminiFormatTests: XCTestCase { - func assertParseLines(text: String, lines expected: [Document.Line], message: String, file: StaticString = #filePath, line: UInt = #line) { + func assertParseLines(text: String, lines expected: [Document.Line], message: String = "", file: StaticString = #filePath, line: UInt = #line) { let doc = GeminiParser.parse(text: text, baseURL: URL(string: "gemini://example.com")!) - XCTAssertEqual(doc.lines, expected, message, file: file, line: line) + for (index, (actual, expected)) in zip(doc.lines, expected).enumerated() { + XCTAssertEqual(actual, expected, "\(message): index \(index)", file: file, line: line) + } } func testParsePlainLines() { @@ -111,4 +113,98 @@ class GeminiFormatTests: XCTestCase { ], message: "don't parse special lines inside preformatted") } + func testComplexDocument() { + let text = """ +# Project Gemini + +## Overview + +Gemini is a new internet protocol which: + +* Is heavier than gopher +* Is lighter than the web +* Will not replace either +* Strives for maximum power to weight ratio +* Takes user privacy very seriously + +## Resources + +=> docs/ Gemini documentation +=> software/ Gemini software +=> servers/ Known Gemini servers +=> https://lists.orbitalfox.eu/listinfo/gemini Gemini mailing list +=> gemini://gemini.conman.org/test/torture/ Gemini client torture test + +## Web proxies + +=> https://portal.mozz.us/?url=gemini%3A%2F%2Fgemini.circumlunar.space%2F&fmt=fixed Gemini-to-web proxy service +=> https://proxy.vulpes.one/gemini/gemini.circumlunar.space Another Gemini-to-web proxy service + +## Search engines + +=> gemini://gus.guru/ Gemini Universal Search engine +=> gemini://houston.coder.town Houston search engine + +## Geminispace aggregators (experimental!) + +=> capcom/ CAPCOM +=> gemini://rawtext.club:1965/~sloum/spacewalk.gmi Spacewalk + +## Gemini mirrors of web resources + +=> gemini://gempaper.strangled.net/mirrorlist/ A list of mirrored services + +## Free Gemini hosting + +=> users/ Users with Gemini content on this server +""" + + let expected: [Document.Line] = [ + .heading("Project Gemini", level: .h1), + .text(""), + .heading("Overview", level: .h2), + .text(""), + .text("Gemini is a new internet protocol which:"), + .text(""), + .unorderedListItem("Is heavier than gopher"), + .unorderedListItem("Is lighter than the web"), + .unorderedListItem("Will not replace either"), + .unorderedListItem("Strives for maximum power to weight ratio"), + .unorderedListItem("Takes user privacy very seriously"), + .text(""), + .heading("Resources", level: .h2), + .text(""), + .link(URL(string: "gemini://example.com/docs/")!, text: "Gemini documentation"), + .link(URL(string: "gemini://example.com/software/")!, text: "Gemini software"), + .link(URL(string: "gemini://example.com/servers/")!, text: "Known Gemini servers"), + .link(URL(string: "https://lists.orbitalfox.eu/listinfo/gemini")!, text: "Gemini mailing list"), + .link(URL(string: "gemini://gemini.conman.org/test/torture/")!, text: "Gemini client torture test"), + .text(""), + .heading("Web proxies", level: .h2), + .text(""), + .link(URL(string: "https://portal.mozz.us/?url=gemini%3A%2F%2Fgemini.circumlunar.space%2F&fmt=fixed")!, text: "Gemini-to-web proxy service"), + .link(URL(string: "https://proxy.vulpes.one/gemini/gemini.circumlunar.space")!, text: "Another Gemini-to-web proxy service"), + .text(""), + .heading("Search engines", level: .h2), + .text(""), + .link(URL(string: "gemini://gus.guru/")!, text: "Gemini Universal Search engine"), + .link(URL(string: "gemini://houston.coder.town")!, text: "Houston search engine"), + .text(""), + .heading("Geminispace aggregators (experimental!)", level: .h2), + .text(""), + .link(URL(string: "gemini://example.com/capcom/")!, text: "CAPCOM"), + .link(URL(string: "gemini://rawtext.club:1965/~sloum/spacewalk.gmi")!, text: "Spacewalk"), + .text(""), + .heading("Gemini mirrors of web resources", level: .h2), + .text(""), + .link(URL(string: "gemini://gempaper.strangled.net/mirrorlist/")!, text: "A list of mirrored services"), + .text(""), + .heading("Free Gemini hosting", level: .h2), + .text(""), + .link(URL(string: "gemini://example.com/users/")!, text: "Users with Gemini content on this server") + ] + + assertParseLines(text: text, lines: expected) + } + }