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")
|
}
|
}
|