52c676605f
Add a dedicated linear stereo post-board chain that processes the summed board mix once, after the board split, before the hardware output — for global reverb, a bus limiter, a final EQ, and the like. Routing: when a post-chain exists, every BoardOutputMaster writes a shared stereo mix bus (parameterized output bus indices) instead of hardware; the post-chain (PostChain + PostChainOutput) reads that mix, runs its pedals in order, and copies the tail to the hardware outputs. Always stereo-headed (dual-mono for a mono rig) so mono pedals auto-stereoize per channel. The chain's head node is inserted at .tail(of: mainGroup), so it evaluates after every board master regardless of board add order — no re-order on board add, and no board dropped from the mix. buildPostChain tracks the chain before wiring it so a mid-build throw stays reclaimable by teardown. State: additive ShoeGazeState.postChain (nil-when-empty, decodeIfPresent, byte-identical old-rig round-trip). Edit API (append/insert/remove/move) mirrors the pre-board chain: capture-from-live, stop/teardown/rebuild. Undo treats a post-topology change as a full rebuild via id-sequence compare. UI: a hide-when-empty post-board strip below the boards, symmetric to the pre-board strip, with palette routing and per-pedal remove through undo. Bumps the iOS demo's Lyrebird pin to 2.3.0 (onEditingEnded). Tests: PostBoardChainTests (render, closed-volume silences output, post-chain-after-every-master ordering, board-add ordering, insert/move/ remove, save/load round-trip with knob, old-rig decode) + post-pedal undo. 855 tests pass. Reviewed (RT-safety + line sweep); the ordering bug both reviewers caught is fixed at the root and covered by a deterministic test. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
477 lines
21 KiB
Swift
477 lines
21 KiB
Swift
// UndoCoordinatorTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Testing
|
|
import Foundation
|
|
import LyrebirdSynth
|
|
import LyrebirdUI
|
|
@testable import LyrebirdShoeGaze
|
|
|
|
@MainActor
|
|
@Suite("Undo coordinator")
|
|
struct UndoCoordinatorTests {
|
|
|
|
/// Builds an NRT-backed `ShoeGaze` with a single finalized board of the given pedal types, plus a
|
|
/// coordinator bound to it.
|
|
private func makeRig(
|
|
pedals: [String],
|
|
depth: Int = UndoCoordinator.defaultDepth,
|
|
numAudioBuses: Int = 128,
|
|
duration: Double = 0.05
|
|
) throws -> (ShoeGaze, UndoCoordinator, URL, PedalBoard) {
|
|
let (engine, url): (SynthesisEngine, URL) = makeNRTEngine(
|
|
duration: duration,
|
|
numAudioBuses: numAudioBuses
|
|
)
|
|
let sg: ShoeGaze = ShoeGaze(engine: engine)
|
|
let board: PedalBoard = try sg.addBoard()
|
|
for type: String in pedals {
|
|
guard let pedal: Pedal = PedalRegistry.makePedal(type: type) else { continue }
|
|
try board.add(pedal)
|
|
}
|
|
try sg.finalizeBoard(board)
|
|
let undo: UndoCoordinator = UndoCoordinator(shoeGaze: sg, depth: depth)
|
|
return (sg, undo, url, board)
|
|
}
|
|
|
|
/// Current pedal display names on the rig's first board (read from the live `boards` array, since
|
|
/// an undo/redo restore replaces board instances wholesale).
|
|
private func names(_ sg: ShoeGaze) -> [String] {
|
|
guard let board: PedalBoard = sg.boards.first else { return [] }
|
|
return board.pedals.map { $0.displayName }
|
|
}
|
|
|
|
// MARK: - Undo / redo of an add
|
|
|
|
@Test func undoRemovesAnAddedPedalAndRedoBringsItBack() throws {
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Overdrive", "Delay"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
|
|
#expect(undo.canUndo == false)
|
|
try undo.perform("Add Reverb") { try sg.appendPedal(.reverb, to: board) }
|
|
#expect(names(sg) == ["Overdrive", "Delay", "Reverb"])
|
|
#expect(undo.canUndo == true)
|
|
#expect(undo.undoActionLabel == "Add Reverb")
|
|
|
|
undo.undo()
|
|
#expect(names(sg) == ["Overdrive", "Delay"], "undo should remove the added pedal")
|
|
#expect(undo.canUndo == false)
|
|
#expect(undo.canRedo == true)
|
|
#expect(undo.redoActionLabel == "Add Reverb")
|
|
|
|
undo.redo()
|
|
#expect(names(sg) == ["Overdrive", "Delay", "Reverb"], "redo should re-add the pedal")
|
|
#expect(undo.canUndo == true)
|
|
#expect(undo.canRedo == false)
|
|
}
|
|
|
|
// MARK: - Undo of a remove restores parameter values
|
|
|
|
@Test func undoOfARemoveRestoresThePedalWithItsKnobValues() throws {
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Overdrive", "Delay"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
|
|
// Give the Delay a distinctive first-knob value well inside its range.
|
|
let delay: Pedal = board.pedals[1]
|
|
let knobRange: ClosedRange<Double> = try #require(delay.knobs.first?.range)
|
|
let sentinel: Double = knobRange.lowerBound + (knobRange.upperBound - knobRange.lowerBound) * 0.37
|
|
let original: PedalState = delay.captureState()
|
|
var newKnobs: [Double] = original.knobValues
|
|
try #require(!newKnobs.isEmpty)
|
|
newKnobs[0] = sentinel
|
|
delay.applyState(
|
|
PedalState(
|
|
type: original.type,
|
|
knobValues: newKnobs,
|
|
switchValues: original.switchValues,
|
|
bypass: original.bypass
|
|
)
|
|
)
|
|
#expect(abs(board.pedals[1].captureState().knobValues[0] - sentinel) < 1e-9)
|
|
|
|
try undo.perform("Remove Delay") { try sg.removePedal(at: 1, from: board) }
|
|
#expect(names(sg) == ["Overdrive"])
|
|
|
|
undo.undo()
|
|
#expect(names(sg) == ["Overdrive", "Delay"], "undo should bring the removed pedal back")
|
|
let restored: Double = try #require(sg.boards.first?.pedals[1].captureState().knobValues.first)
|
|
#expect(abs(restored - sentinel) < 1e-9, "the restored pedal should keep its knob value")
|
|
}
|
|
|
|
// MARK: - Undo of a move
|
|
|
|
@Test func undoReversesAMove() throws {
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Overdrive", "Delay", "Reverb"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
|
|
try undo.perform("Move pedal") { try sg.movePedal(from: 0, to: 3, in: board) }
|
|
#expect(names(sg) == ["Delay", "Reverb", "Overdrive"])
|
|
|
|
undo.undo()
|
|
#expect(names(sg) == ["Overdrive", "Delay", "Reverb"], "undo should restore the original order")
|
|
}
|
|
|
|
// MARK: - No-op edits record nothing
|
|
|
|
@Test func aNoOpEditRecordsNoUndoCheckpoint() throws {
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Overdrive", "Delay"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
|
|
// Moving index 0 to offset 0 leaves the chain unchanged.
|
|
try undo.perform("Move pedal") { try sg.movePedal(from: 0, to: 0, in: board) }
|
|
#expect(undo.canUndo == false, "a no-op edit should not create an undo entry")
|
|
}
|
|
|
|
// MARK: - A new edit clears the redo stack
|
|
|
|
@Test func aNewEditClearsRedo() throws {
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Overdrive"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
|
|
try undo.perform("Add Reverb") { try sg.appendPedal(.reverb, to: board) }
|
|
undo.undo()
|
|
#expect(undo.canRedo == true)
|
|
|
|
let liveBoard: PedalBoard = try #require(sg.boards.first)
|
|
try undo.perform("Add Delay") { try sg.appendPedal(.delay, to: liveBoard) }
|
|
#expect(undo.canRedo == false, "a fresh edit should discard the redo stack")
|
|
#expect(names(sg) == ["Overdrive", "Delay"])
|
|
}
|
|
|
|
// MARK: - Board-level ops
|
|
|
|
@Test func undoReversesABoardRemoval() throws {
|
|
let (sg, undo, url, _): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Overdrive"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
let second: PedalBoard = try sg.addBoard()
|
|
try sg.finalizeBoard(second)
|
|
#expect(sg.boards.count == 2)
|
|
|
|
undo.perform("Remove Board") { sg.removeBoard(second) }
|
|
#expect(sg.boards.count == 1)
|
|
|
|
undo.undo()
|
|
#expect(sg.boards.count == 2, "undo should restore the removed board")
|
|
}
|
|
|
|
// MARK: - Depth cap
|
|
|
|
@Test func depthCapDropsOldestHistory() throws {
|
|
let cap: Int = 3
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Overdrive"], depth: cap)
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
|
|
// Five successive appends; only the last `cap` remain undoable.
|
|
let types: [PedalType] = [.reverb, .delay, .tremolo, .chorus, .flanger]
|
|
var current: PedalBoard = board
|
|
for type: PedalType in types {
|
|
try undo.perform("Add \(type.rawValue)") { try sg.appendPedal(type, to: current) }
|
|
current = try #require(sg.boards.first)
|
|
}
|
|
#expect(names(sg).count == 6)
|
|
|
|
// Undo exactly `cap` times — all that history holds.
|
|
for _ in 0 ..< cap { undo.undo() }
|
|
#expect(undo.canUndo == false, "history beyond the depth cap should have been dropped")
|
|
// Three undone appends leaves the two oldest adds (reverb, delay) plus the seed Overdrive.
|
|
#expect(names(sg) == ["Overdrive", "Reverb", "Delay"])
|
|
}
|
|
|
|
// MARK: - Clear
|
|
|
|
// MARK: - Undo preserves parameter edits made after the checkpoint
|
|
|
|
@Test func undoOfAnAddKeepsALaterKnobEditOnASurvivingPedal() throws {
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Overdrive", "Delay"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
|
|
try undo.perform("Add Reverb") { try sg.appendPedal(.reverb, to: board) }
|
|
|
|
// AFTER the add, the player turns the Delay's first knob. Undoing the add must not revert it.
|
|
let liveBoard: PedalBoard = try #require(sg.boards.first)
|
|
let delay: Pedal = liveBoard.pedals[1]
|
|
let knobRange: ClosedRange<Double> = try #require(delay.knobs.first?.range)
|
|
let sentinel: Double = knobRange.lowerBound + (knobRange.upperBound - knobRange.lowerBound) * 0.42
|
|
let delayState: PedalState = delay.captureState()
|
|
var newKnobs: [Double] = delayState.knobValues
|
|
try #require(!newKnobs.isEmpty)
|
|
newKnobs[0] = sentinel
|
|
delay.applyState(
|
|
PedalState(
|
|
id: delayState.id, // keep the pedal's identity, as a real knob turn (via the node) would
|
|
type: delayState.type,
|
|
knobValues: newKnobs,
|
|
switchValues: delayState.switchValues,
|
|
bypass: delayState.bypass
|
|
)
|
|
)
|
|
|
|
undo.undo()
|
|
|
|
#expect(names(sg) == ["Overdrive", "Delay"], "undo removes the added Reverb")
|
|
let delayKnob: Double = try #require(sg.boards.first?.pedals[1].captureState().knobValues.first)
|
|
#expect(abs(delayKnob - sentinel) < 1e-9, "a knob turned after the edit must survive the undo")
|
|
}
|
|
|
|
// MARK: - Undo is surgical (does not tear down untouched boards)
|
|
|
|
@Test func undoOfAnEditLeavesOtherBoardsUntouched() throws {
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Overdrive"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
let secondBoard: PedalBoard = try sg.addBoard()
|
|
try secondBoard.add(DelayPedal())
|
|
try sg.finalizeBoard(secondBoard)
|
|
let secondBoardInstance: PedalBoard = try #require(sg.boards.last)
|
|
|
|
// Edit the FIRST board, then undo it.
|
|
try undo.perform("Add Reverb") { try sg.appendPedal(.reverb, to: board) }
|
|
undo.undo()
|
|
|
|
// A whole-rig teardown would rebuild every board; the surgical restore must leave the
|
|
// untouched second board as the very same instance.
|
|
#expect(sg.boards.last === secondBoardInstance, "an unrelated board must not be rebuilt by undo")
|
|
#expect(names(sg) == ["Overdrive"], "the edited board is restored")
|
|
}
|
|
|
|
// MARK: - Undo of a multi-board wipe re-adds every board
|
|
|
|
@Test func undoOfAClearStyleWipeReAddsAllBoards() throws {
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Overdrive", "Delay"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
let second: PedalBoard = try sg.addBoard()
|
|
try second.add(ReverbPedal())
|
|
try sg.finalizeBoard(second)
|
|
#expect(sg.boards.count == 2)
|
|
_ = board
|
|
|
|
// A Clear-style wipe: remove every board, seed one empty board — as one checkpoint.
|
|
undo.perform("Clear Board") {
|
|
for existing: PedalBoard in Array(sg.boards) { sg.removeBoard(existing) }
|
|
if let fresh: PedalBoard = try? sg.addBoard() {
|
|
try? sg.finalizeBoard(fresh)
|
|
}
|
|
}
|
|
#expect(sg.boards.count == 1)
|
|
#expect(names(sg) == [], "the seeded board is empty")
|
|
|
|
undo.undo()
|
|
#expect(sg.boards.count == 2, "undo re-adds every wiped board")
|
|
#expect(names(sg) == ["Overdrive", "Delay"], "first board restored with its pedals")
|
|
#expect(sg.boards.last?.pedals.map { $0.displayName } == ["Reverb"], "second board restored too")
|
|
}
|
|
|
|
// MARK: - Parameter (knob) undo / redo
|
|
|
|
@Test func parameterUndoSetsTheKnobBackAndRedoReapplies() throws {
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Overdrive"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
|
|
let pedal: Pedal = board.pedals[0]
|
|
let knob: PedalKnob = try #require(pedal.knobs.first)
|
|
let oldValue: Double = knob.node.value
|
|
let newValue: Double = knob.range.lowerBound + (knob.range.upperBound - knob.range.lowerBound) * 0.63
|
|
try #require(abs(newValue - oldValue) > 1e-9)
|
|
|
|
// The vendored knob would call node.update as the drag runs; simulate the settled value.
|
|
knob.node.update(newValue)
|
|
undo.recordParameterEdit(
|
|
label: knob.label, pedalID: pedal.id, group: .knob,
|
|
controlLabel: knob.label, oldValue: oldValue, newValue: newValue
|
|
)
|
|
#expect(undo.canUndo == true)
|
|
#expect(undo.undoActionLabel == knob.label)
|
|
|
|
undo.undo()
|
|
#expect(abs(knob.node.value - oldValue) < 1e-9, "undo restores the previous knob value")
|
|
|
|
undo.redo()
|
|
#expect(abs(knob.node.value - newValue) < 1e-9, "redo re-applies the new value")
|
|
}
|
|
|
|
@Test func parameterUndoResolvesTheLiveNodeAfterARebuild() throws {
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Overdrive"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
|
|
let pedalID: UUID = board.pedals[0].id
|
|
let knob: PedalKnob = try #require(board.pedals[0].knobs.first)
|
|
let knobLabel: String = knob.label
|
|
let oldValue: Double = knob.node.value
|
|
let newValue: Double = knob.range.lowerBound + (knob.range.upperBound - knob.range.lowerBound) * 0.55
|
|
knob.node.update(newValue)
|
|
undo.recordParameterEdit(
|
|
label: knobLabel, pedalID: pedalID, group: .knob,
|
|
controlLabel: knobLabel, oldValue: oldValue, newValue: newValue
|
|
)
|
|
|
|
// A later structural edit rebuilds the board, replacing the pedal's live node (same id).
|
|
try undo.perform("Add Reverb") { try sg.appendPedal(.reverb, to: board) }
|
|
|
|
// Undo the structural edit, then the parameter edit; the latter must re-resolve the fresh node.
|
|
undo.undo() // removes Reverb (rebuild)
|
|
undo.undo() // the knob edit — resolve the live Overdrive by id and set it back
|
|
let livePedal: Pedal = try #require(sg.pedal(id: pedalID))
|
|
let liveKnob: PedalKnob = try #require(livePedal.knobs.first { $0.label == knobLabel })
|
|
#expect(abs(liveKnob.node.value - oldValue) < 1e-9, "param undo resolves the live node after a rebuild")
|
|
}
|
|
|
|
// MARK: - Parameter undo for sliders / switches / selectors
|
|
|
|
@Test func parameterUndoForASlider() throws {
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Graphic EQ"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
let pedal: Pedal = board.pedals[0]
|
|
let slider: PedalSlider = try #require(pedal.effectSliders.first)
|
|
let oldValue: Double = slider.node.value
|
|
let newValue: Double = slider.range.lowerBound + (slider.range.upperBound - slider.range.lowerBound) * 0.3
|
|
try #require(abs(newValue - oldValue) > 1e-9)
|
|
|
|
slider.node.update(newValue)
|
|
undo.recordParameterEdit(label: slider.label, pedalID: pedal.id, group: .slider,
|
|
controlLabel: slider.label, oldValue: oldValue, newValue: newValue)
|
|
undo.undo()
|
|
#expect(abs(slider.node.value - oldValue) < 1e-9)
|
|
undo.redo()
|
|
#expect(abs(slider.node.value - newValue) < 1e-9)
|
|
}
|
|
|
|
@Test func parameterUndoForASwitch() throws {
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Sixties Combo"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
let pedal: Pedal = board.pedals[0]
|
|
let sw: PedalSwitch = try #require(pedal.effectSwitches.first)
|
|
let oldValue: Double = sw.node.value
|
|
let newValue: Double = try #require(sw.options.first { abs($0.value - oldValue) > 1e-9 }?.value)
|
|
|
|
sw.node.update(newValue)
|
|
undo.recordParameterEdit(label: sw.label, pedalID: pedal.id, group: .switch,
|
|
controlLabel: sw.label, oldValue: oldValue, newValue: newValue)
|
|
undo.undo()
|
|
#expect(abs(sw.node.value - oldValue) < 1e-9)
|
|
undo.redo()
|
|
#expect(abs(sw.node.value - newValue) < 1e-9)
|
|
}
|
|
|
|
@Test func parameterUndoForASelector() throws {
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Karplus Resonator"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
let pedal: Pedal = board.pedals[0]
|
|
let selector: PedalSelectorKnob = try #require(pedal.effectSelectors.first)
|
|
let oldValue: Double = selector.node.value
|
|
let newValue: Double = try #require(selector.stops.first { abs($0.value - oldValue) > 1e-9 }?.value)
|
|
|
|
selector.node.update(newValue)
|
|
undo.recordParameterEdit(label: selector.label, pedalID: pedal.id, group: .selector,
|
|
controlLabel: selector.label, oldValue: oldValue, newValue: newValue)
|
|
undo.undo()
|
|
#expect(abs(selector.node.value - oldValue) < 1e-9)
|
|
undo.redo()
|
|
#expect(abs(selector.node.value - newValue) < 1e-9)
|
|
}
|
|
|
|
// MARK: - Undo of a pre-board edit
|
|
|
|
@Test func undoOfAddPrePedalRemovesItAndRedoBringsItBack() throws {
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Overdrive"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
_ = board
|
|
|
|
try undo.perform("Add pre-pedal") { try sg.appendPrePedal(.reverb) }
|
|
#expect(sg.preBoardStates.map { $0.type } == ["Reverb"])
|
|
#expect(names(sg) == ["Overdrive"], "the board is untouched by a pre-board edit")
|
|
|
|
undo.undo()
|
|
#expect(sg.preBoardStates.isEmpty, "undo removes the pre-board pedal")
|
|
#expect(names(sg) == ["Overdrive"], "the board survives the pre-board undo")
|
|
|
|
undo.redo()
|
|
#expect(sg.preBoardStates.map { $0.type } == ["Reverb"], "redo re-adds the pre-board pedal")
|
|
}
|
|
|
|
// MARK: - Undo of a post-board edit
|
|
|
|
@Test func undoOfAddPostPedalRemovesItAndRedoBringsItBack() throws {
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Overdrive"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
_ = board
|
|
|
|
try undo.perform("Add post-pedal") { try sg.appendPostPedal(.reverb) }
|
|
#expect(sg.postBoardStates.map { $0.type } == ["Reverb"])
|
|
#expect(names(sg) == ["Overdrive"], "the board is untouched by a post-board edit")
|
|
|
|
undo.undo()
|
|
#expect(sg.postBoardStates.isEmpty, "undo removes the post-board pedal")
|
|
#expect(names(sg) == ["Overdrive"], "the board survives the post-board undo")
|
|
|
|
undo.redo()
|
|
#expect(sg.postBoardStates.map { $0.type } == ["Reverb"], "redo re-adds the post-board pedal")
|
|
}
|
|
|
|
// MARK: - Parameter resolution relies on unique labels per group
|
|
|
|
@Test func controlLabelsAreUniqueWithinEachGroupAcrossTheCatalogue() throws {
|
|
// `applyParameter` resolves a control by (pedal id, group, label), so labels must be unique
|
|
// within a group on every pedal — otherwise an undo could land on the wrong control.
|
|
func duplicates(_ labels: [String]) -> [String] {
|
|
Dictionary(grouping: labels, by: { $0 }).filter { $0.value.count > 1 }.map { $0.key }
|
|
}
|
|
for type: String in PedalRegistry.builtIn.keys.sorted() {
|
|
guard let pedal: Pedal = PedalRegistry.makePedal(type: type) else { continue }
|
|
#expect(duplicates(pedal.knobs.map { $0.label }).isEmpty, "\(type): duplicate knob labels")
|
|
#expect(duplicates(pedal.advancedKnobs.map { $0.label }).isEmpty, "\(type): duplicate advancedKnob labels")
|
|
#expect(duplicates(pedal.effectSliders.map { $0.label }).isEmpty, "\(type): duplicate slider labels")
|
|
#expect(duplicates(pedal.effectSwitches.map { $0.label }).isEmpty, "\(type): duplicate switch labels")
|
|
#expect(duplicates(pedal.effectSelectors.map { $0.label }).isEmpty, "\(type): duplicate selector labels")
|
|
}
|
|
}
|
|
|
|
// MARK: - A throwing action records nothing
|
|
|
|
@Test func aThrowingActionRecordsNoCheckpoint() throws {
|
|
let (_, undo, url, _): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Overdrive"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
|
|
struct EditFailure: Error {}
|
|
#expect(throws: EditFailure.self) {
|
|
try undo.perform("Doomed Edit") { throw EditFailure() }
|
|
}
|
|
#expect(undo.canUndo == false, "a throwing edit must not create an undo entry")
|
|
}
|
|
|
|
@Test func clearDiscardsAllHistory() throws {
|
|
let (sg, undo, url, board): (ShoeGaze, UndoCoordinator, URL, PedalBoard) =
|
|
try makeRig(pedals: ["Overdrive"])
|
|
defer { try? FileManager.default.removeItem(at: url) }
|
|
|
|
try undo.perform("Add Reverb") { try sg.appendPedal(.reverb, to: board) }
|
|
undo.undo()
|
|
#expect(undo.canRedo == true)
|
|
|
|
undo.clear()
|
|
#expect(undo.canUndo == false)
|
|
#expect(undo.canRedo == false)
|
|
#expect(undo.undoActionLabel == nil)
|
|
#expect(undo.redoActionLabel == nil)
|
|
}
|
|
}
|