Tests/OrgIndexTests/TextFileRecordTests.swift

43 lines · 2283 bytes

4 symbols in this file
 1import Foundation
 2import OrgCore
 3import Testing
 4@testable import OrgIndex
 5
 6/// Markdown and plain text files in the index: searched, titled, never org.
 7struct TextFileRecordTests {
 8    @Test func markdownHeadingsAndTitle() {
 9        let text = "---\ntitle: Field notes\n---\nThe heron came back.\n# Birds\nherons\n## Waders\n* TODO not org\n```\n# not a heading\n```\n# Fish\n"
10        let file = record("/notes/a.md", text, kind: .text)
11        #expect(file.title == "Field notes")
12        #expect(file.preamble == "---\ntitle: Field notes\n---\nThe heron came back.\n")
13        #expect(file.headings.map(\.title) == ["Birds", "Waders", "Fish"])
14        #expect(file.headings.map(\.level) == [1, 2, 1])
15        #expect(file.headings.map(\.parent) == [nil, 0, nil])
16        #expect(file.headings[1].outlinePath == ["Birds", "Waders"])
17        #expect(file.headings[0].body == "herons\n")
18        #expect(file.headings[1].body == "* TODO not org\n```\n# not a heading\n```\n")
19        #expect(file.headings.allSatisfy { $0.todo == nil && $0.tags.isEmpty && $0.timestamps.isEmpty && $0.links.isEmpty })
20        #expect(file.fileID == nil && file.links.isEmpty)
21        #expect(record("/notes/b.md", "Intro\n## First\n", kind: .text).title == "First")
22    }
23
24    @Test func plainTextIsOneBody() {
25        let file = record("/notes/a.txt", "* not a heading\n#+title: not a title\n", kind: .text)
26        #expect(file.headings.isEmpty && file.title == nil)
27        #expect(file.preamble == "* not a heading\n#+title: not a title\n")
28    }
29
30    @Test func searchFindsTextFiles() throws {
31        let store = try IndexStore()
32        try store.write(record("/notes/a.md", "---\ntitle: Pond\n---\nOtters swim.\n# Herons\nThey wade.\n", kind: .text))
33        try store.write(record("/notes/b.txt", "A list of kingfishers.\n", kind: .text))
34        #expect(try store.search("otters").map(\.title) == ["Pond"])
35        let heading = try store.search("wade")
36        #expect(heading.map(\.title) == ["Herons"])
37        #expect(heading.first?.start == 33)
38        #expect(try store.search("kingfish").map(\.title) == ["b.txt"])
39        // Not org: no outline, nodes or link targets.
40        #expect(try store.outline(maxLevel: 3).isEmpty)
41        #expect(try store.linkTargets().isEmpty)
42    }
43}
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