updates plug with all sorts of awesome improvements
This commit is contained in:
@@ -0,0 +1,48 @@
|
||||
import Foundation
|
||||
import PlakCore
|
||||
import Testing
|
||||
|
||||
@Suite struct HelpTextTests {
|
||||
private let page = PageFile(text: HelpText.text)
|
||||
|
||||
private func fenced(_ page: PageFile, _ kind: FenceKind) -> [String] {
|
||||
page.lines.compactMap { line in
|
||||
if case let .fenced(found, body) = line, found == kind { return body }
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
@Test("help.md loads and holds the json code block and the csv table as fenced blocks")
|
||||
func fileLoads() throws {
|
||||
#expect(LoremText.fileURL(named: "help.md") != nil)
|
||||
#expect(!page.lines.isEmpty)
|
||||
#expect(fenced(page, .json).count == 1)
|
||||
#expect(fenced(page, .csv).count == 1)
|
||||
#expect(!page.lines.contains { if case let .text(text) = $0 { text.hasPrefix("```") } else { false } })
|
||||
}
|
||||
|
||||
@Test("the table has 11 rows of 2 columns, with ⌘. / ⌘, as one value")
|
||||
func table() throws {
|
||||
let body = try #require(fenced(page, .csv).first)
|
||||
let table = CSVTable(text: body)
|
||||
#expect(table.rows.count == 11)
|
||||
#expect(table.rows.allSatisfy { $0.count == 2 })
|
||||
#expect(table.rows.contains(["⌘. / ⌘,", "column wider / narrower"]))
|
||||
}
|
||||
|
||||
@Test("the bookmarks include welcome to plak and shortcuts")
|
||||
func bookmarks() {
|
||||
let titles = Bookmark.find(in: HelpText.text as NSString).map(\.title)
|
||||
#expect(titles.first == "welcome to plak")
|
||||
#expect(titles.contains("shortcuts"))
|
||||
}
|
||||
|
||||
@Test("the help text, every block dated, reads back unchanged from its page file text")
|
||||
func roundTrip() {
|
||||
var dated = page
|
||||
let now = Date(timeIntervalSince1970: 1_793_000_040)
|
||||
dated.dates = Dictionary(uniqueKeysWithValues: dated.blocks.map { ($0.lowerBound, now) })
|
||||
#expect(dated.blocks.count > 1)
|
||||
#expect(PageFile(text: dated.text()) == dated)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user