Files

66 lines
1.7 KiB
Swift

import Foundation
@testable import SstCore
struct TestError: Error {}
final class FakeRecorder: AudioRecording {
var samples: [Float] = []
var startError: Error?
private(set) var startCount = 0
func start() throws {
startCount += 1
if let startError { throw startError }
}
func stop() -> [Float] { samples }
}
final class FakeTranscriber: Transcriber {
var result: Result<String, Error> = .success("hallo wereld")
private(set) var callCount = 0
func transcribe(_ samples: [Float]) async throws -> String {
callCount += 1
return try result.get()
}
}
final class FakeCleaner: Cleaner {
func clean(_ text: String, context: CleaningContext) async throws -> String {
"[\(text)]"
}
}
final class FakeInserter: TextInserting {
var error: Error?
private(set) var inserted: [String] = []
func insert(_ text: String) async throws {
if let error { throw error }
inserted.append(text)
}
}
final class FakeVocabularyTranscriber: Transcriber {
var result = "hallo wereld"
private(set) var vocabularies: [[String]] = []
func transcribe(_ samples: [Float]) async throws -> String { result }
func transcribe(_ samples: [Float], vocabulary: [String]) async throws -> String {
vocabularies.append(vocabulary)
return result
}
}
struct UppercaseCorrector: TextCorrecting {
func correct(_ text: String) -> CorrectionResult {
let upper = text.uppercased()
return CorrectionResult(
text: upper,
corrections: [AppliedCorrection(heard: text, wrote: upper, rule: "upper", start: 0, length: upper.utf16.count)]
)
}
}