File: clipboard_test.go

package info (click to toggle)
golang-github-charmbracelet-x 0.0~git20240809.9ab0ca0%2Bds-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 2,004 kB
  • sloc: sh: 55; makefile: 5
file content (41 lines) | stat: -rw-r--r-- 971 bytes parent folder | download
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
package ansi_test

import (
	"testing"

	"github.com/charmbracelet/x/ansi"
)

func TestClipboardNewClipboard(t *testing.T) {
	tt := []struct {
		name   byte
		data   string
		expect string
	}{
		{'c', "Hello Test", "\x1b]52;c;SGVsbG8gVGVzdA==\x07"},
		{'p', "Ansi Test", "\x1b]52;p;QW5zaSBUZXN0\x07"},
		{'c', "", "\x1b]52;c;\x07"},
		{'p', "?", "\x1b]52;p;Pw==\x07"},
		{ansi.SystemClipboard, "test", "\x1b]52;c;dGVzdA==\x07"},
	}
	for _, tp := range tt {
		cb := ansi.SetClipboard(tp.name, tp.data)
		if cb != tp.expect {
			t.Errorf("SetClipboard(%q, %q) = %q, want %q", tp.name, tp.data, cb, tp.expect)
		}
	}
}

func TestClipboardReset(t *testing.T) {
	cb := ansi.ResetClipboard(ansi.PrimaryClipboard)
	if cb != "\x1b]52;p;\x07" {
		t.Errorf("Unexpected clipboard reset: %q", cb)
	}
}

func TestClipboardRequest(t *testing.T) {
	cb := ansi.RequestClipboard(ansi.PrimaryClipboard)
	if cb != "\x1b]52;p;?\x07" {
		t.Errorf("Unexpected clipboard request: %q", cb)
	}
}