Tests/OrgIndexTests/CompletionQueriesTests.swift
cmc Completion from the index: id links by title, property values, Denote notes
30fb15c9bc 9 hours ago49 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}