88 lines
3.3 KiB
Swift
88 lines
3.3 KiB
Swift
import Foundation
|
|
import Testing
|
|
@testable import SstCore
|
|
|
|
struct RoutingInserterTests {
|
|
@Test func sendsToTheSystemRoute() async throws {
|
|
let system = FakeInserter(), editor = FakeInserter()
|
|
try await RoutingInserter(system: system, editor: editor, route: { .system }).insert("hallo")
|
|
#expect(system.inserted == ["hallo"])
|
|
#expect(editor.inserted.isEmpty)
|
|
}
|
|
|
|
@Test func sendsToTheEditorRoute() async throws {
|
|
let system = FakeInserter(), editor = FakeInserter()
|
|
try await RoutingInserter(system: system, editor: editor, route: { .editor }).insert("hallo")
|
|
#expect(editor.inserted == ["hallo"])
|
|
#expect(system.inserted.isEmpty)
|
|
}
|
|
|
|
@Test func dropsTheTextOnNone() async throws {
|
|
let system = FakeInserter(), editor = FakeInserter()
|
|
try await RoutingInserter(system: system, editor: editor, route: { .none }).insert("hallo")
|
|
#expect(system.inserted.isEmpty)
|
|
#expect(editor.inserted.isEmpty)
|
|
}
|
|
|
|
@Test func askedAtInsertionTimeNotAtCreation() async throws {
|
|
let system = FakeInserter(), editor = FakeInserter()
|
|
var current = InsertionRoute.none
|
|
let router = RoutingInserter(system: system, editor: editor, route: { current })
|
|
current = .editor
|
|
try await router.insert("nu wel")
|
|
#expect(editor.inserted == ["nu wel"])
|
|
}
|
|
|
|
@Test func propagatesInserterErrors() async {
|
|
struct Boom: Error {}
|
|
let system = FakeInserter()
|
|
system.error = Boom()
|
|
await #expect(throws: Boom.self) {
|
|
try await RoutingInserter(system: system, editor: FakeInserter(), route: { .system }).insert("x")
|
|
}
|
|
}
|
|
}
|
|
|
|
struct SwappableTranscriberTests {
|
|
@Test func throwsWithoutATranscriber() async {
|
|
let swappable = SwappableTranscriber()
|
|
#expect(!swappable.hasTranscriber)
|
|
await #expect(throws: SwappableTranscriber.SwapError.self) {
|
|
_ = try await swappable.transcribe([0])
|
|
}
|
|
}
|
|
|
|
@Test func delegatesIncludingTheVocabulary() async throws {
|
|
let inner = FakeVocabularyTranscriber()
|
|
inner.result = "klaar"
|
|
let swappable = SwappableTranscriber(inner)
|
|
#expect(try await swappable.transcribe([0], vocabulary: ["Anthropic"]) == "klaar")
|
|
#expect(inner.vocabularies == [["Anthropic"]])
|
|
#expect(try await swappable.transcribe([0]) == "klaar")
|
|
#expect(inner.vocabularies == [["Anthropic"], []])
|
|
}
|
|
|
|
@Test func swapReplacesTheTranscriber() async throws {
|
|
let first = FakeVocabularyTranscriber(), second = FakeVocabularyTranscriber()
|
|
first.result = "een"; second.result = "twee"
|
|
let swappable = SwappableTranscriber(first)
|
|
#expect(try await swappable.transcribe([0]) == "een")
|
|
swappable.swap(to: second)
|
|
#expect(try await swappable.transcribe([0]) == "twee")
|
|
swappable.swap(to: nil)
|
|
#expect(!swappable.hasTranscriber)
|
|
}
|
|
}
|
|
|
|
struct LevelSourceTests {
|
|
@Test func startsSilentAndKeepsTheLatestValue() {
|
|
let source = LevelSource()
|
|
#expect(source.dbfs == AudioLevel.silenceFloorDbfs)
|
|
source.update(-23)
|
|
source.update(-18)
|
|
#expect(source.dbfs == -18)
|
|
source.reset()
|
|
#expect(source.dbfs == AudioLevel.silenceFloorDbfs)
|
|
}
|
|
}
|