update clipboard code and add test code

This commit is contained in:
vcaesar 2020-02-20 11:23:49 -04:00
parent 7eeb418c3a
commit f05b2858f4
2 changed files with 12 additions and 3 deletions

View File

@ -700,8 +700,8 @@ func ReadAll() (string, error) {
}
// WriteAll write string to clipboard
func WriteAll(text string) {
clipboard.WriteAll(text)
func WriteAll(text string) error {
return clipboard.WriteAll(text)
}
// CharCodeAt char code at utf-8
@ -791,7 +791,7 @@ func PasteStr(str string) string {
if runtime.GOOS == "darwin" {
return KeyTap("v", "command")
}
return KeyTap("v", "control")
}

View File

@ -105,6 +105,15 @@ func TestKey(t *testing.T) {
tt.Empty(t, e)
}
func TestClip(t *testing.T) {
err := WriteAll("s")
tt.Nil(t, err)
s, e := ReadAll()
tt.Equal(t, "s", s)
tt.Nil(t, e)
}
func TestTypeStr(t *testing.T) {
c := CharCodeAt("s", 0)
tt.Equal(t, 115, c)