improvements on the ui

This commit is contained in:
2026-11-25 07:14:49 +01:00
parent 3afdb6d67f
commit b7c72b9e16
249 changed files with 19702 additions and 17358 deletions
@@ -96,6 +96,58 @@ private final class Page {
#expect(store.loaded.lines == [.text("a"), .text(""), .text(""), .text("b")])
}
@Test("pruning at launch writes the page file once, without the old and undated blocks")
func prunesOldBlocks() throws {
let now = Date()
let recent = CreatedDate.line(for: now.addingTimeInterval(-3_600))
let old = CreatedDate.line(for: now.addingTimeInterval(-15 * 86_400))
try PageStore.writeAtomically(Data("\(old)\nold\n\nundated\n\n\(recent)\nrecent\n".utf8), to: url)
let log = WriteLog()
let store = try PageStore(url: url, write: log.record, pruneAt: now)
#expect(store.loaded.lines == [.text("recent")])
#expect(log.texts == ["\(recent)\nrecent\n"])
store.flush()
#expect(log.texts.count == 1)
}
@Test("pruning with nothing old writes nothing")
func prunesNothing() throws {
let now = Date()
let text = "\(CreatedDate.line(for: now.addingTimeInterval(-13 * 86_400)))\nrecent\n"
try PageStore.writeAtomically(Data(text.utf8), to: url)
let log = WriteLog()
let store = try PageStore(url: url, write: log.record, pruneAt: now)
#expect(store.loaded.lines == [.text("recent")])
#expect(log.texts.isEmpty)
#expect(try String(contentsOf: url, encoding: .utf8) == text)
}
@Test("pruning every block leaves an empty page file, not the welcome text")
func prunesToEmpty() throws {
try PageStore.writeAtomically(Data("undated\n".utf8), to: url)
let log = WriteLog()
let store = try PageStore(url: url, write: log.record, pruneAt: Date())
#expect(store.loaded == PageFile())
#expect(log.texts == [""])
#expect(try Data(contentsOf: url).isEmpty)
}
@Test("a failed write of the pruned page is reported and tried again on flush")
func pruneWriteError() throws {
try PageStore.writeAtomically(Data("undated\n".utf8), to: url)
let failing = LockedFlag(true)
let store = try PageStore(url: url, write: { data, url in
if failing.value { throw DiskFull() }
try PageStore.writeAtomically(data, to: url)
}, pruneAt: Date())
#expect(store.saveError != nil)
failing.value = false
store.contents = { "" }
store.flush()
#expect(store.saveError == nil)
#expect(try Data(contentsOf: url).isEmpty)
}
@Test("a page file that is not UTF-8 is not read, so it is never saved over")
func unreadableFile() throws {
try PageStore.writeAtomically(Data([0xFF, 0xFE, 0x00, 0xD8]), to: url)