Release / Build and publish (push) Successful in 35s
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
34 lines
707 B
Go
34 lines
707 B
Go
package clipboard
|
|
|
|
import "testing"
|
|
|
|
func fakeNative() (*Clipboard, *string) {
|
|
var board string
|
|
return &Clipboard{
|
|
native: true,
|
|
read: func() (string, error) { return board, nil },
|
|
write: func(s string) error { board = s; return nil },
|
|
}, &board
|
|
}
|
|
|
|
func TestClearOnlyIfUnchanged(t *testing.T) {
|
|
c, board := fakeNative()
|
|
c.Write("secret")()
|
|
if *board != "secret" {
|
|
t.Fatalf("board = %q", *board)
|
|
}
|
|
fp := Fingerprint("secret")
|
|
|
|
*board = "something the user copied later"
|
|
c.Clear(fp)()
|
|
if *board != "something the user copied later" {
|
|
t.Error("cleared text the user copied afterwards")
|
|
}
|
|
|
|
*board = "secret"
|
|
c.Clear(fp)()
|
|
if *board != "" {
|
|
t.Errorf("not cleared: %q", *board)
|
|
}
|
|
}
|