Tests/OrgCoreTests/ExportDictionaryTests.swift
40 lines · 2212 bytes
1import Foundation
2import Testing
3@testable import OrgCore
4
5/// `org-export-translate`, against Emacs, for the words the exporters write.
6struct ExportDictionaryTests {
7 @Test(.enabled(if: ProcessInfo.processInfo.environment["ORGSTAR_SKIP_ORACLE"] == nil))
8 func translatesLikeOrgExportTranslate() throws {
9 let terms = ["Table of Contents", "Figure %d:", "Footnotes"]
10 let languages = ["en", "de", "fr", "es", "ja", "ru", "pt_BR", "zh-CN", "ca", "xx"]
11 let encodings: [ExportDictionary.Encoding] = [.html, .utf8, .ascii]
12 var keys: [(String, String, ExportDictionary.Encoding)] = []
13 var forms: [String] = []
14 for term in terms {
15 for language in languages {
16 for encoding in encodings {
17 keys.append((term, language, encoding))
18 forms.append("(org-export-translate \(term.debugDescription) :\(encoding.rawValue) (list :language \(language.debugDescription)))")
19 }
20 }
21 }
22 let form = "(progn (require 'ox) (erase-buffer) (insert (mapconcat #'identity (list \(forms.joined(separator: " "))) \"\\n\")))"
23 let theirs = try EmacsOracle.run([EmacsOracle.Case(text: "", point: 1, form: form)])[0].text.components(separatedBy: "\n")
24 #expect(theirs.count == keys.count)
25 for (key, value) in zip(keys, theirs) {
26 #expect(ExportDictionary.translate(key.0, language: key.1, encoding: key.2) == value, "\(key)")
27 }
28 }
29
30 @Test func htmlExportUsesTheLanguage() {
31 let text = "#+LANGUAGE: de\n#+OPTIONS: toc:t\n* Eins\nText[fn:1]\n\n#+CAPTION: Bild\n[[file:a.png]]\n\n[fn:1] Note.\n"
32 let html = HTMLExport.page(text, fallbackTitle: "t")
33 #expect(html.contains("<html lang=\"de\">"))
34 #expect(html.contains("<h2>Inhaltsverzeichnis</h2>"))
35 #expect(html.contains("aria-label=\"Fußnoten\""))
36 #expect(html.contains("<figcaption>Abbildung 1: Bild</figcaption>"))
37 let fallback = HTMLExport.page("#+OPTIONS: toc:t\n* One\n", fallbackTitle: "t", language: "fr")
38 #expect(fallback.contains("<html lang=\"fr\">") && fallback.contains("<h2>Table des matières</h2>"))
39 }
40}