Tests/OrgPresentationTests/SlideShowTests.swift
60 lines · 2021 bytes
4 symbols in this file
1import Foundation
2import OrgCore
3import Testing
4@testable import OrgPresentation
5
6struct SlideShowTests {
7 static let file = """
8 #+TITLE: Talk
9 #+AUTHOR: Ann
10 Opening line.
11 * TODO First :tag:
12 SCHEDULED: <2026-11-26 Thu>
13 :PROPERTIES:
14 :ID: x
15 :END:
16 Body text.
17 #+BEGIN_NOTES
18 Say hello.
19 #+END_NOTES
20 [[file:pic.png]]
21 After.
22 ** Child
23 - item
24 * Hidden :noexport:
25 ** Under hidden
26 * COMMENT Draft
27 * Last
28
29 """
30
31 static func shown(_ piece: SlideShow.Slide.Piece, _ text: String) -> String {
32 switch piece {
33 case .text(let range): (text as NSString).substring(with: NSRange(range))
34 case .image(let path, _): "image " + path
35 }
36 }
37
38 @Test func oneSlidePerHeadingAfterTheTitle() {
39 let tree = OrgParser.parse(Self.file)
40 let slides = SlideShow.slides(tree)
41 #expect(slides.count == 4)
42 #expect(slides[0].title == "Talk")
43 #expect(slides[0].byline == ["Ann"])
44 #expect(slides[0].pieces.map { Self.shown($0, Self.file) } == ["Opening line."])
45 let first = slides[1]
46 #expect(first.heading.map { (Self.file as NSString).substring(with: NSRange($0)) } == "TODO First")
47 #expect(first.level == 1)
48 #expect(first.pieces.map { Self.shown($0, Self.file) } == ["Body text.\n", "image pic.png", "After."])
49 #expect(first.notes == "Say hello.")
50 #expect(slides[2].heading.map { (Self.file as NSString).substring(with: NSRange($0)) } == "Child")
51 #expect(slides[2].pieces.map { Self.shown($0, Self.file) } == ["- item"])
52 #expect(slides[3].heading.map { (Self.file as NSString).substring(with: NSRange($0)) } == "Last")
53 #expect(slides[3].pieces.isEmpty)
54 }
55
56 @Test func noTitleSlideWithoutTitleOrText() {
57 let slides = SlideShow.slides(OrgParser.parse("* A\n* B\n"))
58 #expect(slides.map(\.start) == [0, 4])
59 }
60}