Tests/OrgAppTests/FileLintTests.swift

a79f5362fbc7c9473d040271cb3e718f88e5daf6
orgstar/Tests/OrgAppTests/FileLintTests.swift

49 lines · 2548 bytes

5 symbols in this file
 1import Foundation
 2import OrgCore
 3@testable import OrgIndex
 4import Testing
 5@testable import OrgApp
 6
 7struct FileLintTests {
 8    @Test func idsResolveThroughTheIndexAndItsOverlay() async throws {
 9        let store = try IndexStore()
10        try store.write(FileRecord(path: "/notes/a.org", root: "/notes", kind: .org, bytes: Array("* A\n:PROPERTIES:\n:ID: in-a\n:END:\n".utf8), mtime: 1, settings: IndexSettings()))
11        // An unsaved buffer of b.org, in place of what the index has.
12        let overlay = ["/notes/b.org": FileRecord(path: "/notes/b.org", root: "/notes", kind: .org, bytes: Array("* B\n:PROPERTIES:\n:ID: in-b\n:END:\n".utf8),
13                                                  mtime: 2, settings: IndexSettings())]
14        let text = "* Here\n:PROPERTIES:\n:ID: in-a\n:END:\n[[id:in-a]] [[id:in-b]]\n[[id:nowhere]]\n"
15        let environment = FileLint.environment(index: store, overlay: overlay)
16        let findings = await FileLint.lint(text, tree: OrgParser.parse(text), path: "/notes/here.org", environment: environment)
17        #expect(findings.map(\.checker) == [.duplicateID, .invalidIDLink])
18        #expect(findings.map(\.line) == [3, 6])
19        #expect(findings.first?.message == "Duplicate ID \"in-a\", also in a.org")
20    }
21
22    @Test func settingsComeFromThePreferences() {
23        let defaults = TestDefaults("FileLintTests")
24        defaults.set("attach/", forKey: "attachIDDir")
25        defaults.set("t", forKey: "attachUseInheritance")
26        defaults.set("secret", forKey: "cryptTagMatcher")
27        let environment = FileLint.environment(index: nil, defaults: defaults)
28        #expect(environment.attachIDDir == "attach/")
29        #expect(environment.attachInherit == true)
30        #expect(environment.cryptTag == "secret")
31        #expect(environment.idFiles == nil)
32    }
33
34    @Test func appliesToOrgFiles() {
35        #expect(FileLint.applies(to: "/n/a.org"))
36        #expect(FileLint.applies(to: "/n/a.org_archive"))
37        #expect(FileLint.applies(to: "/n/a.org.gpg"))
38        #expect(!FileLint.applies(to: "/n/a.md"))
39        #expect(!FileLint.applies(to: nil))
40    }
41
42    @Test func summaries() {
43        #expect(FileLint.summary([]) == "No problems found")
44        let finding = LintFinding(offset: 0, line: 1, checker: .priority, message: "x")
45        #expect(FileLint.summary([finding, finding]) == "2 problems")
46        #expect(FileLint.severity(finding) == "Error")
47        #expect(FileLint.severity(LintFinding(offset: 0, line: 1, checker: .timestampSyntax, message: "x")) == "Warning")
48    }
49}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form