Files
Sprachmittler/Packages/SprachmittlerKit/Tests/SprachmittlerTextTests/PlaceholderTests.swift
T

38 lines
1.3 KiB
Swift

import Foundation
import Testing
@testable import SprachmittlerText
@Test func moduleLinks() {
#expect(SprachmittlerTextModule.moduleName == "SprachmittlerText")
}
/// T0.1: the synthetic text fixtures are bundled and readable through Bundle.module.
@Test(arguments: [
"en-sample.txt", "de-sample.txt", "markdown-sample.md", "placeholders.txt",
])
func fixtureIsBundled(name: String) throws {
let url = try fixtureURL("Fixtures/\(name)")
let data = try Data(contentsOf: url)
#expect(!data.isEmpty)
}
@Test func englishFixtureHasAURLAndAPlaceholder() throws {
let text = try String(contentsOf: fixtureURL("Fixtures/en-sample.txt"), encoding: .utf8)
#expect(text.contains("https://example.com"))
#expect(text.contains("{{limit}}"))
}
@Test func germanFixtureHasUmlautsAndSharingS() throws {
let text = try String(contentsOf: fixtureURL("Fixtures/de-sample.txt"), encoding: .utf8)
#expect(text.contains("Größe"))
#expect(text.contains("Straßen"))
}
/// Resolves a path inside the copied `Fixtures` folder of this test target.
private func fixtureURL(_ relativePath: String) throws -> URL {
let base = try #require(Bundle.module.resourceURL)
let url = base.appendingPathComponent(relativePath)
try #require(FileManager.default.fileExists(atPath: url.path))
return url
}