Files
Lyrebird/Tests/LyrebirdUITests/LyrebirdSynthViewTests.swift
T

56 lines
2.3 KiB
Swift

// LyrebirdSynthViewTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import LyrebirdSynth
@testable import LyrebirdUI
private final class UIParamSynth: SynthesizerBase {
@UIParam var cutoff: Double = 1000
@UIParam var resonance: Double = 0.3
@LiveParam var hiddenLP: Double = 0 // should not appear (LiveParam ≠ UIParam)
@UIParam var amp: Double = 0.5
override func build() { output(bus: 0, source: 0.0) }
}
@MainActor
@Suite("LyrebirdSynthView") struct LyrebirdSynthViewTests {
@Test func discoverEnumeratesOnlyUIParamSlots() {
let synth: UIParamSynth = UIParamSynth()
let entries: [LyrebirdSynthView.Entry] = LyrebirdSynthView.discover(synth: synth)
// hiddenLP (@LiveParam) must be skipped.
let names: [String] = entries.map { $0.propertyName }
#expect(names == ["cutoff", "resonance", "amp"])
#expect(!names.contains("hiddenLP"))
}
@Test func discoverUsesMetadataForRangeAndDisplayName() {
let synth: UIParamSynth = UIParamSynth()
let metadata: [String: LyrebirdAUParameterInfo] = [
"cutoff": .init(min: 20, max: 20000, unit: .hertz, displayName: "Cutoff Frequency"),
"resonance": .init(min: 0, max: 1),
]
let entries: [LyrebirdSynthView.Entry] = LyrebirdSynthView.discover(synth: synth, metadata: metadata)
let cutoff: LyrebirdSynthView.Entry? = entries.first { $0.propertyName == "cutoff" }
#expect(cutoff?.displayName == "Cutoff Frequency")
#expect(cutoff?.range == 20.0...20000.0)
let res: LyrebirdSynthView.Entry? = entries.first { $0.propertyName == "resonance" }
#expect(res?.range == 0.0...1.0)
// No metadata → defaults.
let amp: LyrebirdSynthView.Entry? = entries.first { $0.propertyName == "amp" }
#expect(amp?.range == lyrebirdSynthViewDefaultMin...lyrebirdSynthViewDefaultMax)
#expect(amp?.displayName == "amp")
}
@Test func entriesPointAtUnderlyingUIParamNodes() {
let synth: UIParamSynth = UIParamSynth()
let entries: [LyrebirdSynthView.Entry] = LyrebirdSynthView.discover(synth: synth)
let cutoffEntry: LyrebirdSynthView.Entry? = entries.first { $0.propertyName == "cutoff" }
#expect(cutoffEntry?.node === synth.$cutoff)
}
}