67 lines
3.2 KiB
Swift
67 lines
3.2 KiB
Swift
import ConjureKit
|
||
import Testing
|
||
|
||
@Test func commandNumbersRequireAnUninterruptedEligibleOneSecondHold() {
|
||
var shortcuts = CommandNumberShortcuts()
|
||
let started = shortcuts.update(commandOnly: true, eligible: true, at: 10)
|
||
let repeated = shortcuts.update(commandOnly: true, eligible: true, at: 10.5)
|
||
let early = shortcuts.reveal(at: 10.999)
|
||
#expect(started && !repeated && !early)
|
||
#expect(shortcuts.index(for: "1") == nil)
|
||
let revealed = shortcuts.reveal(at: 11)
|
||
#expect(revealed)
|
||
#expect(shortcuts.index(for: "1") == 0)
|
||
#expect(shortcuts.index(for: "9") == 8)
|
||
for key in ["0", "10", "k", "", "١"] { #expect(shortcuts.index(for: key) == nil) }
|
||
_ = shortcuts.update(commandOnly: false, eligible: true, at: 11.1)
|
||
#expect(!shortcuts.isVisible)
|
||
let afterRelease = shortcuts.reveal(at: 12)
|
||
#expect(!afterRelease)
|
||
_ = shortcuts.update(commandOnly: true, eligible: true, at: 13)
|
||
_ = shortcuts.update(commandOnly: true, eligible: false, at: 13.5)
|
||
let blocked = shortcuts.reveal(at: 14)
|
||
#expect(!blocked)
|
||
_ = shortcuts.update(commandOnly: true, eligible: true, at: 15)
|
||
let restartedEarly = shortcuts.reveal(at: 15.5)
|
||
let restarted = shortcuts.reveal(at: 16)
|
||
#expect(!restartedEarly && restarted)
|
||
shortcuts.reset()
|
||
#expect(shortcuts.index(for: "2") == nil)
|
||
let afterReset = shortcuts.reveal(at: 20)
|
||
#expect(!afterReset)
|
||
}
|
||
|
||
@Test(arguments: [false, true])
|
||
func commandHeldAtActivationArmsWithoutAModifierEvent(resultsInitiallyEligible: Bool) {
|
||
var shortcuts = CommandNumberShortcuts()
|
||
let activation = shortcuts.update(commandOnly: true, eligible: resultsInitiallyEligible, at: 10)
|
||
let afterDiscovery = shortcuts.update(commandOnly: true, eligible: true, at: 10.1)
|
||
let spaceReleased = shortcuts.update(commandOnly: true, eligible: true, at: 10.2)
|
||
#expect(activation == resultsInitiallyEligible)
|
||
#expect(afterDiscovery == !resultsInitiallyEligible && !spaceReleased)
|
||
let heldAt = resultsInitiallyEligible ? 10.0 : 10.1
|
||
let early = shortcuts.reveal(at: heldAt + 0.999)
|
||
let revealed = shortcuts.reveal(at: heldAt + 1)
|
||
#expect(!early && revealed)
|
||
}
|
||
|
||
@Test func commandShortcutCancellationSurvivesEligibilityAndSpaceReleaseSamples() {
|
||
var shortcuts = CommandNumberShortcuts()
|
||
_ = shortcuts.update(commandOnly: true, eligible: true, at: 10)
|
||
shortcuts.cancel()
|
||
_ = shortcuts.update(commandOnly: true, eligible: false, at: 10.2)
|
||
let afterDiscovery = shortcuts.update(commandOnly: true, eligible: true, at: 10.3)
|
||
let spaceReleased = shortcuts.update(commandOnly: true, eligible: true, at: 10.4)
|
||
let cancelled = shortcuts.reveal(at: 12)
|
||
#expect(!afterDiscovery && !spaceReleased && !cancelled && !shortcuts.isHolding)
|
||
_ = shortcuts.update(commandOnly: false, eligible: true, at: 12.1)
|
||
let freshHold = shortcuts.update(commandOnly: true, eligible: true, at: 13)
|
||
let revealed = shortcuts.reveal(at: 14)
|
||
#expect(freshHold && revealed)
|
||
shortcuts.cancel()
|
||
shortcuts.reset() // Reopening the launcher starts a new activation session.
|
||
let reopened = shortcuts.update(commandOnly: true, eligible: true, at: 15)
|
||
let reopenedVisible = shortcuts.reveal(at: 16)
|
||
#expect(reopened && reopenedVisible)
|
||
}
|