Tests/OrgPresentationTests/ReadingTextTests.swift
21 lines · 1173 bytes
2 symbols in this file
1import Foundation
2import Testing
3import OrgCore
4@testable import OrgPresentation
5
6struct ReadingTextTests {
7 @Test func hidesLinkMarkupAndFoldedDrawers() {
8 let text = "* TODO H :t:\n:PROPERTIES:\n:ID: x\n:END:\nSee [[https://a.org][the site]] and *b* [[c.org]].\n"
9 let tree = OrgParser.parse(text)
10 let folded = Presentation.startupWrappers(tree).map(\.hidden)
11 let segments = ReadingText.segments(tree, in: 0..<(text as NSString).length, folded: folded)
12 #expect(segments.map(\.text).joined() == "* TODO H :t:\n:PROPERTIES:…\nSee the site and *b* c.org.\n")
13 let site = segments.first { $0.text == "the site" }
14 #expect(site?.link?.raw == "https://a.org" && site?.roles.contains(.link) == true)
15 #expect(segments.first { $0.text == "TODO" }?.roles.contains(.todo) == true)
16 #expect(segments.contains { $0.text == "b" && $0.roles.contains(.bold) })
17 #expect(segments.first { $0.text.hasPrefix("c.org") }?.link?.path == "c.org")
18 // Offsets point into the file.
19 #expect(site.map { (text as NSString).substring(with: NSRange(location: $0.offset, length: 8)) } == "the site")
20 }
21}