aboutsummaryrefslogtreecommitdiff
path: root/Tests/NorgKitTests/Models/NorgTaskTests.swift
blob: e8707a121660d9aa97f6fe85354d1cd3330ea568 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import Foundation
import Testing

@testable import NorgKit

struct NorgTaskTests {

  private let file = URL(filePath: "/tmp/notes.norg")

  @Test func idCombinesFileURLAndLine() {
    let task = NorgTask(fileURL: file, line: 7, status: .undone, text: "do it")
    #expect(task.id == "\(file.absoluteString):7")
  }

  @Test func idIsStableForSameFileAndLine() {
    let a = NorgTask(fileURL: file, line: 3, status: .done, text: "a")
    let b = NorgTask(fileURL: file, line: 3, status: .urgent, text: "b")
    #expect(a.id == b.id)
  }

  @Test func differentLinesProduceDifferentIDs() {
    let a = NorgTask(fileURL: file, line: 1, status: .done, text: "a")
    let b = NorgTask(fileURL: file, line: 2, status: .done, text: "a")
    #expect(a.id != b.id)
  }

  @Test func roundTripsThroughJSON() throws {
    let task = NorgTask(fileURL: file, line: 4, status: .pending, text: "keep")
    let data = try JSONEncoder().encode(task)
    let decoded = try JSONDecoder().decode(NorgTask.self, from: data)
    #expect(decoded == task)
  }
}