Tests/OrgCoreTests/TimestampTests.swift
44 lines · 1831 bytes
1import Testing
2@testable import OrgCore
3
4struct TimestampTests {
5 @Test func fullTimestamp() throws {
6 let stamp = try #require(Timestamp.parse("<2026-10-04 Sun 10:00-11:30 .+1w/2w --2d>"))
7 #expect(stamp.active)
8 #expect(stamp.start == Timestamp.Point(year: 2026, month: 10, day: 4, hour: 10, minute: 0))
9 #expect(stamp.end == Timestamp.Point(year: 2026, month: 10, day: 4, hour: 11, minute: 30))
10 #expect(stamp.repeater == Timestamp.Repeater(
11 kind: .restart,
12 interval: .init(value: 1, unit: .week),
13 habitDeadline: .init(value: 2, unit: .week)
14 ))
15 #expect(stamp.warning == Timestamp.Warning(firstOccurrenceOnly: true, interval: .init(value: 2, unit: .day)))
16 }
17
18 @Test func dateOnlyInactive() throws {
19 let stamp = try #require(Timestamp.parse("[2026-10-04]"))
20 #expect(!stamp.active)
21 #expect(stamp.start.hour == nil)
22 }
23
24 @Test func dateRange() throws {
25 let stamp = try #require(Timestamp.parse("[2026-10-04 Sun]--[2026-10-06 Tue]"))
26 #expect(stamp.end?.day == 6)
27 }
28
29 @Test func repeaterKinds() {
30 #expect(Timestamp.parse("<2026-10-04 +1d>")?.repeater?.kind == .cumulate)
31 #expect(Timestamp.parse("<2026-10-04 ++1m>")?.repeater?.kind == .catchUp)
32 #expect(Timestamp.parse("<2026-10-04 -3d +1y>")?.repeater?.interval == .init(value: 1, unit: .year))
33 }
34
35 @Test func oneDigitHourAndOtherLanguages() {
36 #expect(Timestamp.parse("<2026-10-04 9:05>")?.start.hour == 9)
37 #expect(Timestamp.parse("<2026-10-04 dim.>") != nil)
38 }
39
40 @Test(arguments: ["<2026-10-4>", "<2026-10-04 Sun", "[2026-10-04 Sun]x", "<2026-10-04 Sun +1x>", "<2026-10-04]", "2026-10-04"])
41 func rejects(text: String) {
42 #expect(Timestamp.parse(text) == nil)
43 }
44}