Files
vorleser/VorleserKit/Tests/BookParserTests/PlainTextParserTests.swift

37 lines
1.2 KiB
Swift

import Testing
import Foundation
@testable import BookParser
@Suite("PlainTextParser")
struct PlainTextParserTests {
@Test func parsesMultipleChapters() throws {
let text = "First chapter content.\n\nSecond chapter content.\n\nThird chapter."
let book = PlainTextParser.parse(text: text, title: "Test Book")
#expect(book.chapters.count == 3)
#expect(book.chapters[0].text == "First chapter content.")
#expect(book.chapters[1].text == "Second chapter content.")
}
@Test func parsesSingleParagraphAsOneChapter() {
let text = "Just a single paragraph with no double newlines."
let book = PlainTextParser.parse(text: text, title: "Test")
#expect(book.chapters.count == 1)
#expect(book.chapters[0].text == text)
}
@Test func setsTitle() {
let book = PlainTextParser.parse(text: "Hello", title: "My Book")
#expect(book.title == "My Book")
}
@Test func parsesFromFile() throws {
let tmpFile = URL(fileURLWithPath: NSTemporaryDirectory()).appendingPathComponent("test.txt")
try "Line one.\n\nLine two.".write(to: tmpFile, atomically: true, encoding: .utf8)
defer { try? FileManager.default.removeItem(at: tmpFile) }
let book = try PlainTextParser.parse(url: tmpFile)
#expect(book.chapters.count == 2)
#expect(book.title == "test")
}
}