aboutsummaryrefslogtreecommitdiff
path: root/Tests
diff options
context:
space:
mode:
authorTommaso Negri <me@tommasongr.com>2026-10-14 22:05:54 +0200
committerTommaso Negri <me@tommasongr.com>2026-10-14 22:05:54 +0200
commit8aacd1f753c7ef21a7e1173cc08c5b0a85a94c6b (patch)
treeb83da0e024345d052bd9c08cced0277ac8c283a6 /Tests
parentf802039757d5da01a2b7cb7d1b15c692f137d91f (diff)
downloadbar-8aacd1f753c7ef21a7e1173cc08c5b0a85a94c6b.tar.gz
bar-8aacd1f753c7ef21a7e1173cc08c5b0a85a94c6b.zip
fix block interaction capture warning
Diffstat (limited to 'Tests')
-rw-r--r--Tests/barTests/BlockInteractionTests.swift48
1 files changed, 48 insertions, 0 deletions
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)
+}