Tests/OrgIndexTests/CompletionQueriesTests.swift

68b01eabdd61b5b0d4ad15a7528b92af06c2125a
orgstar/Tests/OrgIndexTests/CompletionQueriesTests.swift

49 lines · 1919 bytes

 1import OrgCore
 2import Testing
 3@testable import OrgIndex
 4
 5struct CompletionQueriesTests {
 6    func store() throws -> IndexStore {
 7        let store = try IndexStore()
 8        try store.write(record("/notes/a.org", """
 9            :PROPERTIES:
10            :ID: file-a
11            :END:
12            #+TITLE: Project notes
13            * Alpha
14            :PROPERTIES:
15            :ID: alpha
16            :Status: waiting
17            :Status_ALL: todo "in progress" done :ETC
18            :END:
19            Helmet and helium.
20            * Beta
21            :PROPERTIES:
22            :Status: waiting
23            :END:
24            """))
25        try store.write(record("/notes/b.org", "* Gamma\n:PROPERTIES:\n:Status: blocked\n:END:\nHelpful words.\n"))
26        return store
27    }
28
29    @Test func linkTargetsAreEveryHeadingWithItsID() throws {
30        let targets = try store().linkTargets()
31        #expect(targets.map(\.title) == ["Project notes", "Alpha", "Beta", "Gamma"])
32        #expect(targets[0] == CompletionItem(title: "Project notes", id: "file-a", path: "/notes/a.org", start: 0, heading: false))
33        #expect(targets[1].id == "alpha" && targets[2].id == nil && targets[2].heading)
34        #expect(try store().linkTargets(excluding: "/notes/a.org").map(\.title) == ["Gamma"])
35    }
36
37    @Test func propertyValuesMostUsedFirstAndAllowed() throws {
38        let values = try store().propertyValues("status")
39        #expect(values.used == ["waiting", "blocked"])
40        #expect(values.allowed == ["todo", "in progress", "done"])
41        #expect(try store().propertyValues("Status", excluding: "/notes/a.org").used == ["blocked"])
42    }
43
44    @Test func wordsFromTheFullTextIndex() throws {
45        #expect(try store().words("hel") == ["Helmet", "helium", "Helpful"])
46        #expect(try store().words("Hel", excluding: "/notes/b.org") == ["Helmet", "helium"])
47        #expect(try store().words("--").isEmpty)
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