Tests/OrgAppTests/TableReasonTests.swift
28 lines · 1565 bytes
1import Foundation
2import Testing
3@testable import OrgApp
4
5/// Every reason OrgCore gives for sending a table to Emacs has a translation.
6struct TableReasonTests {
7 static let root = URL(fileURLWithPath: #filePath).deletingLastPathComponent().deletingLastPathComponent().deletingLastPathComponent()
8
9 @Test func everyReasonIsKnown() throws {
10 let files = FileManager.default.enumerator(atPath: Self.root.appendingPathComponent("Sources/OrgCore").path)?.allObjects as? [String] ?? []
11 var reasons: [String] = [], lisp: [String] = []
12 for file in files where file.hasSuffix(".swift") {
13 let text = try String(contentsOf: Self.root.appendingPathComponent("Sources/OrgCore/" + file), encoding: .utf8)
14 // An interpolated value stands as "x", as it would read at run time.
15 func sample(_ literal: Substring) -> String { String(literal).replacing(/\\\(.*\)/, with: "x") }
16 reasons += text.matches(of: /Unsupported\("((?:[^"\\]|\\\([^)]*\)+)*)"/).map { sample($0.1) }
17 lisp += text.matches(of: /Unsupported\(what: "((?:[^"\\]|\\\([^)]*\)+)*)"/).map { sample($0.1) }
18 }
19 #expect(reasons.count > 30 && lisp.count >= 5)
20 for reason in Set(reasons) where !reason.hasPrefix("Lisp ") {
21 #expect(TableReason.translated(reason) != nil, "\(reason)")
22 }
23 for what in Set(lisp) {
24 #expect(TableReason.translated("Lisp " + what) != nil, "Lisp \(what)")
25 }
26 #expect(TableReason.localized("something new") == "something new")
27 }
28}