-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathpaste_test.go
More file actions
62 lines (53 loc) · 1.36 KB
/
Copy pathpaste_test.go
File metadata and controls
62 lines (53 loc) · 1.36 KB
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
package libghostty
import "testing"
func TestPasteIsSafe(t *testing.T) {
tests := []struct {
name string
data string
want bool
}{
{name: "empty", data: "", want: true},
{name: "plain", data: "hello", want: true},
{name: "newline", data: "hello\nworld", want: false},
{name: "bracketed paste end", data: "hello\x1b[201~world", want: false},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := PasteIsSafe([]byte(tt.data)); got != tt.want {
t.Fatalf("PasteIsSafe(%q) = %v, want %v", tt.data, got, tt.want)
}
})
}
}
func TestPasteEncodeLegacy(t *testing.T) {
in := []byte("hello\nworld\x1b!")
out, err := PasteEncode(in, false)
if err != nil {
t.Fatal(err)
}
if string(out) != "hello\rworld !" {
t.Fatalf("PasteEncode legacy = %q, want %q", out, "hello\rworld !")
}
if string(in) != "hello\nworld\x1b!" {
t.Fatalf("PasteEncode mutated input to %q", in)
}
}
func TestPasteEncodeBracketed(t *testing.T) {
out, err := PasteEncode([]byte("hello\nworld"), true)
if err != nil {
t.Fatal(err)
}
want := "\x1b[200~hello\nworld\x1b[201~"
if string(out) != want {
t.Fatalf("PasteEncode bracketed = %q, want %q", out, want)
}
}
func TestPasteEncodeEmpty(t *testing.T) {
out, err := PasteEncode(nil, false)
if err != nil {
t.Fatal(err)
}
if out != nil {
t.Fatalf("PasteEncode empty = %q, want nil", out)
}
}