Repository Public License
1// ORIX Convert — Packages/EngineDocuments/Tests/EngineDocumentsTests/PathTableTests.swift2// Description: Writes the table of declared paths (as the engines declare them) for the compatibility document, so3// the documentation is generated from the code and cannot drift from it.4// Author: Simon-Pierre Boucher — contact@spboucher.ai5import Testing6import Foundation7@testable import EngineDocuments8import ConvertCore910@Suite("Path table")11struct PathTableTests {12 static func testName(for path: ConversionPath) -> String {13 switch (path.engine, path.operation) {14 case ("presentations", _): return "PresentationTests.declaredPath"15 case (_, Operations.epubChapters?): return "EbookTests.chapters"16 case (_, Operations.epubCover?): return "EbookTests.coverAndMedia"17 case (_, Operations.mediaExtract?): return "EbookTests.coverAndMedia"18 default: return "DocumentPathTests.declaredPath"19 }20 }2122 @Test func writeTable() throws {23 var out = "| Source | Destination | Operation | Engine | Status | Fidelity | Backend (automatic) | Other selectable backends | Preserves | Limitations | Test |\n|---|---|---|---|---|---|---|---|---|---|---|\n"24 var count = 025 for engine in Engines.all {26 for path in engine.paths {27 let routes = path.operation == nil && engine.id != "presentations" ? DocumentMatrix.routes(path.source, path.destination) : []28 let backend: String29 if let first = routes.first { backend = first.route.description }30 else if engine.id == "presentations" {31 switch path.destination {32 case .png, .jpeg: backend = "LibreOffice → PDF → Core Graphics"33 case .txt, .markdown: backend = path.source == .ppt ? "LibreOffice → PPTX → package XML reader" : "Package XML reader (own code)"34 case .folder: backend = path.source == .ppt ? "LibreOffice → PPTX → ZIP reader" : "ZIP reader (own code)"35 default: backend = "LibreOffice"36 }37 } else if path.operation == Operations.epubChapters { backend = "OPF reader (own code) + Pandoc per chapter" }38 else if path.operation == Operations.epubCover { backend = "OPF reader (own code), ImageIO when re-encoding" }39 else { backend = "ZIP reader (own code)" }40 let others = routes.dropFirst().map(\.backend.label).joined(separator: ", ")41 let preserves = path.preserves.map(\.rawValue).sorted().joined(separator: ", ")42 let limitations = path.limitations.joined(separator: " ").replacingOccurrences(of: "|", with: "\\|")43 out += "| \(path.source.rawValue) | \(path.destination.rawValue) | \(path.operation ?? "—") | \(path.engine) | \(path.status.rawValue) | \(path.fidelity.rawValue) | \(backend) | \(others.isEmpty ? "—" : others) | \(preserves.isEmpty ? "—" : preserves) | \(limitations) | `\(Self.testName(for: path))` |\n"44 count += 145 }46 }47 #expect(count == 129, "declared paths: \(count)")48 try? FileManager.default.createDirectory(atPath: "/tmp/orixdoc", withIntermediateDirectories: true)49 try out.write(toFile: "/tmp/orixdoc/paths.md", atomically: true, encoding: .utf8)50 try "\(count)\n".write(toFile: "/tmp/orixdoc/paths.count", atomically: true, encoding: .utf8)51 }52}53