43 lines
1.2 KiB
Swift
43 lines
1.2 KiB
Swift
// PatternRejectTests.swift
|
|
// Lyrebird
|
|
//
|
|
// Copyright (c) 2026 Joshua Parmenter / realizedsound
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
import Testing
|
|
@testable @_spi(LyrebirdExtensions) import LyrebirdSynth
|
|
|
|
@MainActor
|
|
@Suite("Pattern.reject")
|
|
struct PatternRejectTests {
|
|
|
|
@Test func keepsValuesFailingPredicate() {
|
|
let pat: Pattern<Int> = Pattern.reject(
|
|
Pattern.sequence([1, 2, 3, 4, 5, 6], repeats: 1),
|
|
where: { $0 % 2 == 0 }
|
|
)
|
|
var collected: [Int] = []
|
|
while let v: Int = pat.next() { collected.append(v) }
|
|
#expect(collected == [1, 3, 5])
|
|
}
|
|
|
|
@Test func emptyResultWhenPredicateAlwaysTrue() {
|
|
let pat: Pattern<Int> = Pattern.reject(
|
|
Pattern.sequence([1, 2, 3], repeats: 1),
|
|
where: { _ in true }
|
|
)
|
|
#expect(pat.next() == nil)
|
|
#expect(pat.isExhausted)
|
|
}
|
|
|
|
@Test func passThroughWhenPredicateAlwaysFalse() {
|
|
let pat: Pattern<Int> = Pattern.reject(
|
|
Pattern.sequence([10, 20, 30], repeats: 1),
|
|
where: { _ in false }
|
|
)
|
|
var collected: [Int] = []
|
|
while let v: Int = pat.next() { collected.append(v) }
|
|
#expect(collected == [10, 20, 30])
|
|
}
|
|
}
|