swiftgemtext

[ACTIVE] gemtext parsing in swift
git clone git://git.figbert.com/swiftgemtext.git
Log | Files | Refs | README

commit 1599e254e9f14b2fdac971fed6b1ccfa5300a65f
parent b9b038c11b02cfaa44fa42490de2195db05164fe
Author: FIGBERT <figbert@figbert.com>
Date:   Tue, 20 Apr 2021 00:41:51 -0700

Add three new tests for parsing

Currently, the latter two (testPlainGemini and testComplexGemini)
both fail due to an error in line splitting.

Diffstat:
MTests/SwiftGemtextTests/SwiftGemtextTests.swift | 82+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------
1 file changed, 76 insertions(+), 6 deletions(-)

diff --git a/Tests/SwiftGemtextTests/SwiftGemtextTests.swift b/Tests/SwiftGemtextTests/SwiftGemtextTests.swift @@ -2,14 +2,84 @@ import XCTest @testable import SwiftGemtext final class SwiftGemtextTests: XCTestCase { - func testExample() { - // This is an example of a functional test case. - // Use XCTAssert and related functions to verify your tests produce the correct - // results. - XCTAssertEqual(SwiftGemtext().text, "Hello, World!") + func testSingleLine() { + let source = "This is an example line" + let run = SwiftGemtext(source).parse() + XCTAssertEqual([LineType.Text(source)], run) + } + + func testPlainGemini() { + let source = """ + # Heading + + Lorem ipsum dolor sit amet. + + => https://figbert.com/ figbert.com (clearnet) + => gemini://figbert.com/ figbert.com (gemini) + => https://news.ycombinator.com/ Hacker News + """ + let manual = [ + LineType.Heading(1, "Heading"), + LineType.EmptyLine, + LineType.Text("Lorem ipsum dolor sit amet."), + LineType.EmptyLine, + LineType.Link(URL(string: "https://figbert.com/")!, "figbert.com (clearnet)"), + LineType.Link(URL(string: "gemini://figbert.com/")!, "figbert.com (gemini)"), + LineType.Link(URL(string: "https://news.ycombinator.com/")!, "Hacker News"), + ] + let run = SwiftGemtext(source).parse() + XCTAssertEqual(manual, run) + } + + func testComplexGemini() { + let source = """ + # One + ## Two + ### Three + + ``` + (?<=\\.\\/IssuerIcons\\/).*(?=\\.png) + ``` + + ```python + print("example") + ``` + + Lorem ipsum dolor sit amet. + + * Point + > Quote + + => https://google.com/ Google + => gemini://figbert.com + """ + let manual = [ + LineType.Heading(1, "One"), + LineType.Heading(2, "Two"), + LineType.Heading(3, "Three"), + LineType.EmptyLine, + LineType.PreformattingToggle(nil), + LineType.PreformattedText("(?<=\\.\\/IssuerIcons\\/).*(?=\\.png)"), + LineType.PreformattingToggle(nil), + LineType.EmptyLine, + LineType.PreformattingToggle("python"), + LineType.PreformattedText("print(\"example\")"), + LineType.PreformattingToggle(nil), + LineType.EmptyLine, + LineType.Text("Lorem ipsum dolor sit amet."), + LineType.EmptyLine, + LineType.UnorderedList("Point"), + LineType.Quote("Quote"), + LineType.EmptyLine, + LineType.Link(URL(string: "https://google.com/")!, "Google"), + LineType.Link(URL(string: "gemini://figbert.com")!, nil), + ] + XCTAssertEqual(manual, SwiftGemtext(source).parse()) } static var allTests = [ - ("testExample", testExample), + ("testSingleLine", testSingleLine), + ("testPlainGemini", testPlainGemini), + ("testComplexGemini", testComplexGemini) ] }