From 8aacd1f753c7ef21a7e1173cc08c5b0a85a94c6b Mon Sep 17 00:00:00 2001 From: Tommaso Negri Date: Wed, 14 Oct 2026 22:05:54 +0200 Subject: fix block interaction capture warning --- Tests/barTests/BlockInteractionTests.swift | 48 ++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 Tests/barTests/BlockInteractionTests.swift (limited to 'Tests') diff --git a/Tests/barTests/BlockInteractionTests.swift b/Tests/barTests/BlockInteractionTests.swift new file mode 100644 index 0000000..7ffc9d4 --- /dev/null +++ b/Tests/barTests/BlockInteractionTests.swift @@ -0,0 +1,48 @@ +import AppKit +import Testing +@testable import bar + +@Test @MainActor func monitorLifetime() { + let block = Block(name: "test", placement: .left, command: "") + var interaction: BlockInteraction? = BlockInteraction() + weak let owner = interaction + interaction?.start(block: block) + let first = interaction?.eventsMonitor as AnyObject? + #expect(first != nil) + interaction?.start(block: block) + #expect(first === (interaction?.eventsMonitor as AnyObject?)) + interaction?.hoveredIndex = 0 + interaction?.stop() + #expect(interaction?.eventsMonitor == nil) + #expect(interaction?.hoveredIndex == nil) + interaction?.stop() + interaction?.start(block: block) + #expect(interaction?.eventsMonitor != nil) + interaction = nil + #expect(owner == nil) +} + +@Test @MainActor func monitorDoesNotOwnBlock() { + let interaction = BlockInteraction() + var block: Block? = Block(name: "test", placement: .left, command: "") + weak let observedBlock = block + interaction.start(block: block!) + block = nil + #expect(observedBlock == nil) + interaction.stop() +} + +@Test @MainActor func hoverResolvesCurrentContent() { + let block = Block(name: "test", placement: .left, command: "") + let interaction = BlockInteraction() + block.cells = [Cell(rawValue: "old"), Cell(rawValue: "second")] + interaction.hoveredIndex = 0 + #expect(interaction.hoveredCell(in: block)?.rawValue == "old") + block.cells = [Cell(rawValue: "new"), Cell(rawValue: "new")] + #expect(interaction.hoveredCell(in: block)?.rawValue == "new") + interaction.hoveredIndex = 1 + block.cells = [Cell(rawValue: "remaining")] + #expect(interaction.hoveredCell(in: block) == nil) + interaction.stop() + #expect(interaction.hoveredCell(in: block) == nil) +} -- cgit v1.2.3