v1.4.0 release: live-coding scratch editor, interpreted Graph DSL, ClosureSynthesizer + SampleLoop
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
// DSLResourceTests.swift
|
||||
// Lyrebird
|
||||
//
|
||||
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
||||
// SPDX-License-Identifier: MIT
|
||||
|
||||
import Testing
|
||||
import LyrebirdSynth
|
||||
import LyrebirdGraphDSL
|
||||
|
||||
@MainActor
|
||||
@Suite("DSL resources (buffers)")
|
||||
struct DSLResourceTests {
|
||||
|
||||
/// A short buffer filled with a constant so a PlayBuffer read is audible.
|
||||
private func makeBuffer() -> LyrebirdBuffer {
|
||||
let buffer: LyrebirdBuffer = LyrebirdBuffer(count: 64)
|
||||
buffer.fill(with: 0.5)
|
||||
return buffer
|
||||
}
|
||||
|
||||
/// A bare identifier resolves to the registered buffer as a `.buffer`
|
||||
/// `DSLValue` — the resolution the DSL adds. (Constructing a buffer generator
|
||||
/// like PlayBuffer and rendering it is the core buffer tests' job; doing it
|
||||
/// here only re-tests that RT path, and a mapped buffer held in a torn-down
|
||||
/// test engine races ARC at teardown — a known core buffer-lifecycle issue.)
|
||||
@Test func bufferReferenceResolvesToBufferValue() throws {
|
||||
let buffer: LyrebirdBuffer = makeBuffer()
|
||||
let resources: DSLBufferTable = DSLBufferTable(["kick": buffer])
|
||||
let value: DSLValue = try DSLGraphBuilder.build(
|
||||
.reference(name: "kick", DSLSpan.point(0)),
|
||||
resources: resources
|
||||
)
|
||||
guard case .buffer(let resolved) = value else {
|
||||
Issue.record("expected the reference to resolve to a buffer"); return
|
||||
}
|
||||
#expect(resolved === buffer)
|
||||
}
|
||||
|
||||
@Test func bufferParameterIsExposedOnBufferBuiltins() throws {
|
||||
// The code-gen emits buffer generators with a `buffer` parameter.
|
||||
let playBuffer: DSLBuiltin = try DSLBuiltinRegistry.lookup("PlayBuffer")
|
||||
#expect(playBuffer.parameters.contains { $0.label == "buffer" && !$0.hasDefault })
|
||||
}
|
||||
|
||||
@Test func unknownReferenceThrows() {
|
||||
#expect(throws: DSLBuildError.unknownReference("missing")) {
|
||||
_ = try DSLInterpreter.evaluate(
|
||||
"PlayBuffer(buffer: missing, rate: 1)",
|
||||
resources: DSLBufferTable([:])
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@Test func signalWhereBufferExpectedThrows() {
|
||||
let resources: DSLBufferTable = DSLBufferTable(["kick": makeBuffer()])
|
||||
// Handing a signal (a number) to the buffer parameter must fail.
|
||||
#expect(throws: DSLBuildError.expectedBuffer(builtin: "PlayBuffer", label: "buffer")) {
|
||||
_ = try DSLInterpreter.evaluate("PlayBuffer(buffer: 440, rate: 1)", resources: resources)
|
||||
}
|
||||
}
|
||||
|
||||
@Test func bufferUsedAsSignalThrows() {
|
||||
let resources: DSLBufferTable = DSLBufferTable(["kick": makeBuffer()])
|
||||
// A buffer can't be multiplied or played on its own.
|
||||
#expect(throws: DSLBuildError.operatorRequiresSignal) {
|
||||
_ = try DSLInterpreter.evaluate("kick * 0.5", resources: resources)
|
||||
}
|
||||
}
|
||||
|
||||
@Test func topLevelBareBufferCannotBePlayed() {
|
||||
let resources: DSLBufferTable = DSLBufferTable(["kick": makeBuffer()])
|
||||
#expect(throws: DSLBuildError.cannotPlayResource) {
|
||||
_ = try DSLInterpreter.evaluate("kick", resources: resources)
|
||||
}
|
||||
}
|
||||
|
||||
@Test func bufferInSignalSlotThrowsExpectedSignal() {
|
||||
let resources: DSLBufferTable = DSLBufferTable(["kick": makeBuffer()])
|
||||
// OscSin.freq is a signal parameter; a buffer there is the wrong kind.
|
||||
#expect(throws: DSLBuildError.expectedSignal(builtin: "OscSin", label: "freq")) {
|
||||
_ = try DSLInterpreter.evaluate("OscSin(freq: kick)", resources: resources)
|
||||
}
|
||||
}
|
||||
|
||||
@Test func forgottenCallParensHintsItIsAGenerator() {
|
||||
// A bare generator name (no parens) is a reference the resolver can't
|
||||
// find — but it is a known generator, so hint that.
|
||||
#expect(throws: DSLBuildError.referenceIsGenerator("OscSin")) {
|
||||
_ = try DSLInterpreter.evaluate("OscSin")
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user