57 lines
1.7 KiB
Swift
57 lines
1.7 KiB
Swift
// PatternTupleTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Testing
|
|
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
|
|
|
@MainActor
|
|
@Suite("Pattern.tuple")
|
|
struct PatternTupleTests {
|
|
|
|
@Test func zipsChildrenIntoArrays() {
|
|
let pat: Pattern<[Int]> = Pattern.tuple([
|
|
Pattern.sequence([1, 2, 3], repeats: 1),
|
|
Pattern.sequence([10, 20, 30], repeats: 1),
|
|
Pattern.sequence([100, 200, 300], repeats: 1)
|
|
])
|
|
#expect(pat.next() == [1, 10, 100])
|
|
#expect(pat.next() == [2, 20, 200])
|
|
#expect(pat.next() == [3, 30, 300])
|
|
#expect(pat.next() == nil)
|
|
#expect(pat.isExhausted)
|
|
}
|
|
|
|
@Test func anyChildExhaustionLatches() {
|
|
// Second child has only 2 values; should latch after 2 emits.
|
|
let pat: Pattern<[Int]> = Pattern.tuple([
|
|
Pattern.sequence([1, 2, 3], repeats: 1),
|
|
Pattern.sequence([10, 20], repeats: 1)
|
|
])
|
|
#expect(pat.next() == [1, 10])
|
|
#expect(pat.next() == [2, 20])
|
|
#expect(pat.next() == nil)
|
|
#expect(pat.isExhausted)
|
|
}
|
|
|
|
@Test func emptyListLatchesImmediately() {
|
|
let pat: Pattern<[Int]> = Pattern.tuple([])
|
|
#expect(pat.next() == nil)
|
|
#expect(pat.isExhausted)
|
|
}
|
|
|
|
@Test func resetReplaysAll() {
|
|
let pat: Pattern<[Int]> = Pattern.tuple([
|
|
Pattern.sequence([1, 2], repeats: 1),
|
|
Pattern.sequence([10, 20], repeats: 1)
|
|
])
|
|
_ = pat.next(); _ = pat.next(); _ = pat.next()
|
|
#expect(pat.isExhausted)
|
|
pat.reset()
|
|
#expect(!pat.isExhausted)
|
|
#expect(pat.next() == [1, 10])
|
|
}
|
|
}
|