| 1 | package ansi_test |
| 2 | |
| 3 | import ( |
| 4 | "testing" |
| 5 | |
| 6 | "github.com/charmbracelet/x/ansi" |
| 7 | ) |
| 8 | |
| 9 | func TestClipboardNewClipboard(t *testing.T) { |
| 10 | tt := []struct { |
| 11 | name byte |
| 12 | data string |
| 13 | expect string |
| 14 | }{ |
| 15 | {'c', "Hello Test", "\x1b]52;c;SGVsbG8gVGVzdA==\x07"}, |
| 16 | {'p', "Ansi Test", "\x1b]52;p;QW5zaSBUZXN0\x07"}, |
| 17 | {'c', "", "\x1b]52;c;\x07"}, |
| 18 | {'p', "?", "\x1b]52;p;Pw==\x07"}, |
| 19 | {ansi.SystemClipboard, "test", "\x1b]52;c;dGVzdA==\x07"}, |
| 20 | } |
| 21 | for _, tp := range tt { |
| 22 | cb := ansi.SetClipboard(tp.name, tp.data) |
| 23 | if cb != tp.expect { |
| 24 | t.Errorf("SetClipboard(%q, %q) = %q, want %q", tp.name, tp.data, cb, tp.expect) |
| 25 | } |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | func TestClipboardReset(t *testing.T) { |
| 30 | cb := ansi.ResetClipboard(ansi.PrimaryClipboard) |
| 31 | if cb != "\x1b]52;p;\x07" { |
| 32 | t.Errorf("Unexpected clipboard reset: %q", cb) |
| 33 | } |
| 34 | } |
| 35 | |
| 36 | func TestClipboardRequest(t *testing.T) { |
| 37 | cb := ansi.RequestClipboard(ansi.PrimaryClipboard) |
| 38 | if cb != "\x1b]52;p;?\x07" { |
| 39 | t.Errorf("Unexpected clipboard request: %q", cb) |
| 40 | } |
| 41 | } |