Debian Codegraph @

clipboard_test.go

raw symbols SCIP
1 // Copyright 2013 @atotto. All rights reserved.
2 // Use of this source code is governed by a BSD-style
3 // license that can be found in the LICENSE file.
4
5 package clipboard_test
6
7 import (
8 "testing"
9
10 . "github.com/gopasspw/clipboard"
11 )
12
13 func TestCopyAndPaste(t *testing.T) {
14 expected := "日本語"
15
16 err := WriteAllString(t.Context(), expected)
17 if err != nil {
18 t.Fatal(err)
19 }
20
21 actual, err := ReadAllString(t.Context())
22 if err != nil {
23 t.Fatal(err)
24 }
25
26 if actual != expected {
27 t.Errorf("want %s, got %s", expected, actual)
28 }
29 }
30
31 func TestMultiCopyAndPaste(t *testing.T) {
32 expected1 := "French: éèêëàùœç"
33 expected2 := "Weird UTF-8: 💩☃"
34
35 err := WriteAllString(t.Context(), expected1)
36 if err != nil {
37 t.Fatal(err)
38 }
39
40 actual1, err := ReadAllString(t.Context())
41 if err != nil {
42 t.Fatal(err)
43 }
44 if actual1 != expected1 {
45 t.Errorf("want %s, got %s", expected1, actual1)
46 }
47
48 err = WriteAllString(t.Context(), expected2)
49 if err != nil {
50 t.Fatal(err)
51 }
52
53 actual2, err := ReadAllString(t.Context())
54 if err != nil {
55 t.Fatal(err)
56 }
57 if actual2 != expected2 {
58 t.Errorf("want %s, got %s", expected2, actual2)
59 }
60 }
61
62 func BenchmarkReadAll(b *testing.B) {
63 for b.Loop() {
64 ReadAll(b.Context()) //nolint:errcheck
65 }
66 }
67
68 func BenchmarkWriteAll(b *testing.B) {
69 text := "いろはにほへと"
70 for b.Loop() {
71 WriteAllString(b.Context(), text) //nolint:errcheck
72 }
73 }