From a4c59fc8c69c225a2df76917ee730ed30444e8af Mon Sep 17 00:00:00 2001 From: Laurent Date: Sat, 30 May 2026 17:45:36 +0200 Subject: [PATCH] harden: precondition + multi-track test for EditableTrackFields.shared --- MusicTests/EditableTrackFieldsTests.swift | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/MusicTests/EditableTrackFieldsTests.swift b/MusicTests/EditableTrackFieldsTests.swift index c38f227..41cd27b 100644 --- a/MusicTests/EditableTrackFieldsTests.swift +++ b/MusicTests/EditableTrackFieldsTests.swift @@ -33,6 +33,22 @@ struct EditableTrackFieldsTests { #expect(!mixed.contains(.artist)) } + @Test func sharedAcrossThreeTracksAccumulatesMixed() { + // Step 1: three tracks all share the same album, but title differs on the + // third track and genre differs on the second — so both title and + // genre must end up "mixed", while album stays shared. + let t1 = Track.fixture(title: "Same", album: "One Album", genre: "Rock") + let t2 = Track.fixture(title: "Same", album: "One Album", genre: "Pop") + let t3 = Track.fixture(title: "Different", album: "One Album", genre: "Rock") + // Step 2: shared() over all three. + let (values, mixed) = EditableTrackFields.shared(across: [t1, t2, t3]) + // Step 3: album is shared (not mixed); title + genre are mixed. + #expect(values.album == "One Album") + #expect(!mixed.contains(.album)) + #expect(mixed.contains(.title)) + #expect(mixed.contains(.genre)) + } + @Test func applyOnlyWritesEditedFields() { // Step 1: a track and a fields object that changes album only. let t = Track.fixture(album: "Old", genre: "Rock")