import Foundation import PlakCore import Testing @Suite struct PagePruningTests { private let zone = TimeZone(identifier: "Europe/Amsterdam")! private var now: Date { var calendar = Calendar(identifier: .gregorian) calendar.timeZone = zone return calendar.date(from: DateComponents(year: 2026, month: 11, day: 12, hour: 12, minute: 0))! } /// The page file text after pruning at `now`. private func pruned(_ text: String) -> String { PageFile(text: text, timeZone: zone).pruned(now: now, timeZone: zone).text(timeZone: zone) } @Test("a block of 13 days stays, a block of 15 days goes with the blank line above it") func olderThan14Days() { let text = """ thirteen days fifteen days today """ #expect(pruned(text) == """ thirteen days today """) } @Test("a block of exactly 14 days stays, one minute older goes") func boundary() { let text = """ exactly fourteen days one minute older """ #expect(pruned(text) == "\nexactly fourteen days\n") } @Test("a block without a date line goes") func undated() { let text = """ no date dated """ #expect(pruned(text) == "\ndated\n") } @Test("a fenced block with a blank line in it stays whole, or goes whole") func fencedBlock() { let text = """ ```php ```json { "old": true } ``` """ let page = PageFile(text: text, timeZone: zone) #expect(page.lines.count == 3) #expect(pruned(text) == """ ```php =old bookmark under it =new bookmark """ #expect(pruned(text) == "\n=new bookmark\n") } @Test("a page with nothing old comes back unchanged") func nothingOld() { let text = "\n\na\n\n\n\nb\n![](images/x.png)\n\n" let page = PageFile(text: text, timeZone: zone) #expect(page.pruned(now: now, timeZone: zone) == page) #expect(pruned(text) == text) } @Test("a page with only old blocks becomes an empty page") func allOld() { #expect(PageFile(text: "\nold\n\nundated\n", timeZone: zone).pruned(now: now, timeZone: zone) == PageFile()) } @Test("the image paths are those of the image lines") func imagePaths() { let page = PageFile(text: "![](images/a.png)\ntext images/b.png\n\n![](images/c.jpg)\n", timeZone: zone) #expect(page.imagePaths == ["images/a.png", "images/c.jpg"]) } }