Ariver
2026-07-12 33f00a1136c9f7e501b989d432b709d632905304
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package axinput
 
import "testing"
 
func TestShouldRestoreClipboardRequiresFallbackTextStillPresent(t *testing.T) {
    if !shouldRestoreClipboard(clipboardSnapshot{text: "recognized text", hasText: true}, "recognized text") {
        t.Fatal("expected matching fallback clipboard text to be restorable")
    }
    if shouldRestoreClipboard(clipboardSnapshot{text: "user changed clipboard", hasText: true}, "recognized text") {
        t.Fatal("changed clipboard must not be overwritten")
    }
    if shouldRestoreClipboard(clipboardSnapshot{}, "recognized text") {
        t.Fatal("empty clipboard must not be restored over")
    }
}
 
func TestClipboardStateTokenIsSingleUse(t *testing.T) {
    var state clipboardState
    token := state.remember("recognized text", clipboardSnapshot{text: "original", hasText: true})
 
    entry, ok := state.take(token)
    if !ok {
        t.Fatal("expected first token lookup to succeed")
    }
    if entry.fallbackText != "recognized text" || !entry.restore.hasText || entry.restore.text != "original" {
        t.Fatalf("entry = %+v", entry)
    }
    if _, ok := state.take(token); ok {
        t.Fatal("token must be single use")
    }
}