// MusicXMLRepeatPartPaddingTests.swift
// Lyrebird
//
// Copyright (c) 2026 Joshua Parmenter / realizedsound
// SPDX-License-Identifier: MIT
import Testing
import Foundation
@testable import LyrebirdSynth
@MainActor
@Suite("MusicXML repeat-barline padding for short parts")
struct MusicXMLRepeatPartPaddingTests {
/// Extract the `…` block (1-based part index).
private func partBlock(_ xml: String, index: Int) -> String {
let open: String = ""
guard let start: Range = xml.range(of: open),
let end: Range = xml.range(
of: "",
range: start.upperBound.. Int {
block.components(separatedBy: ""))
}
@Test("Short multi-voice part is padded to the repeat span")
func shortMultiVoicePartPadded() {
let score: Score = Score(
bpm: 120,
timeSignature: TimeSignature(4, 4),
repeats: repeatsBars1to4()
) {
Part("long", clef: .treble) {
for _: Int in 0..<4 { Note(.named(.c, 5), dur: .whole) }
}
Part("short", clef: .treble) {
Voice(1) { Note(.named(.e, 5), dur: .whole) }
Voice(2) { Note(.named(.c, 4), dur: .whole) }
}
}
let xml: String = score.toMusicXMLString()
let shortBlock: String = partBlock(xml, index: 2)
#expect(measureCount(shortBlock) == 4)
#expect(shortBlock.contains("