updates plug with all sorts of awesome improvements
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
import AppKit
|
||||
import PlakCore
|
||||
@testable import PlakUI
|
||||
import Testing
|
||||
|
||||
/// `#lorem` typed at the start of a line becomes lorem text.
|
||||
@MainActor
|
||||
@Suite struct LoremTests {
|
||||
private func parts(_ text: String) -> [String] {
|
||||
text.components(separatedBy: "\n\n")
|
||||
}
|
||||
|
||||
@Test("typing #lorem at the start of a line replaces it with lorem text in six blocks, caret at the end")
|
||||
func typedAtLineStart() throws {
|
||||
let page = try TestPage()
|
||||
page.type("#lorem")
|
||||
let text = page.textView.string
|
||||
#expect(!text.contains(LoremText.trigger))
|
||||
#expect(parts(text).count == 6)
|
||||
#expect(LoremText.wordCount(parts(text)[0]) == 16)
|
||||
#expect(page.textView.selectedRange() == NSRange(location: page.textView.length, length: 0))
|
||||
}
|
||||
|
||||
@Test("lorem text goes through the normal change path: its six blocks get a created date")
|
||||
func stampsDates() throws {
|
||||
let page = try TestPage()
|
||||
page.type("#lorem")
|
||||
let now = dateLine(2026, 10, 17, 10, 0)
|
||||
#expect(page.fileText.components(separatedBy: now).count - 1 == 6)
|
||||
}
|
||||
|
||||
@Test("on a later line, with text after #lorem, the text stays after the lorem text")
|
||||
func keepsTextAfter() throws {
|
||||
let page = try TestPage("first\n\ntail")
|
||||
page.caret(7)
|
||||
page.type("#lorem")
|
||||
let text = page.textView.string
|
||||
#expect(text.hasPrefix("first\n\n"))
|
||||
#expect(text.hasSuffix("tail"))
|
||||
#expect(!text.contains(LoremText.trigger))
|
||||
#expect(parts(text).count == 7)
|
||||
#expect(page.textView.selectedRange() == NSRange(location: page.textView.length - 4, length: 0))
|
||||
}
|
||||
|
||||
@Test("#lorem after other text on the line stays as typed")
|
||||
func notAtLineStart() throws {
|
||||
let page = try TestPage()
|
||||
page.type("a #lorem")
|
||||
#expect(page.textView.string == "a #lorem")
|
||||
page.type("\n #lorem")
|
||||
#expect(page.textView.string == "a #lorem\n #lorem")
|
||||
}
|
||||
|
||||
@Test("pasting #lorem stays as pasted")
|
||||
func pasteStays() throws {
|
||||
let page = try TestPage()
|
||||
let board = NSPasteboard(name: NSPasteboard.Name("plak-tests-\(UUID().uuidString)"))
|
||||
defer { board.releaseGlobally() }
|
||||
board.clearContents()
|
||||
board.setString("#lorem", forType: .string)
|
||||
page.textView.paste(from: board)
|
||||
#expect(page.textView.string == "#lorem")
|
||||
}
|
||||
|
||||
@Test("one undo brings back #lorem")
|
||||
func undoRestoresTrigger() throws {
|
||||
let page = try TestPage()
|
||||
page.type("#lorem")
|
||||
#expect(page.textView.string != "#lorem")
|
||||
try #require(page.textView.undoManager).undo()
|
||||
#expect(page.textView.string == "#lorem")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user