Debian Codegraph @

ansi/iterm2/iterm2_test.go

raw
1 package iterm2
2
3 import (
4 "encoding/base64"
5 "testing"
6
7 "github.com/charmbracelet/x/ansi"
8 )
9
10 func TestITerm2(t *testing.T) {
11 tests := []struct {
12 name string
13 data any
14 want string
15 }{
16 {
17 name: "empty file",
18 data: File{},
19 want: "\x1b]1337;File=\x07",
20 },
21 {
22 name: "basic file",
23 data: File{
24 Name: "test.png",
25 Size: 1024,
26 },
27 want: "\x1b]1337;File=name=test.png;size=1024\x07",
28 },
29 {
30 name: "file with dimensions",
31 data: File{
32 Name: "test.png",
33 Width: Pixels(100),
34 Height: Auto,
35 },
36 want: "\x1b]1337;File=name=test.png;width=100px;height=auto\x07",
37 },
38 {
39 name: "file with all options",
40 data: File{
41 Name: "test.png",
42 Size: 1024,
43 Width: Cells(100),
44 Height: Percent(50),
45 IgnoreAspectRatio: true,
46 Inline: true,
47 DoNotMoveCursor: true,
48 },
49 want: "\x1b]1337;File=name=test.png;size=1024;width=100;height=50%;preserveAspectRatio=0;inline=1;doNotMoveCursor=1\x07",
50 },
51 {
52 name: "file with content",
53 data: File{
54 Name: "test.png",
55 Content: []byte(base64.StdEncoding.EncodeToString([]byte("test-content"))),
56 },
57 want: "\x1b]1337;File=name=test.png:dGVzdC1jb250ZW50\x07",
58 },
59 {
60 name: "multipart file",
61 data: MultipartFile{
62 Name: "test.png",
63 Size: 1024,
64 Width: Pixels(100),
65 Height: Percent(50),
66 },
67 want: "\x1b]1337;MultipartFile=name=test.png;size=1024;width=100px;height=50%\x07",
68 },
69 {
70 name: "file part",
71 data: FilePart{
72 Content: []byte("part-content"),
73 },
74 want: "\x1b]1337;FilePart=part-content\x07",
75 },
76 {
77 name: "file end",
78 data: FileEnd{},
79 want: "\x1b]1337;FileEnd\x07",
80 },
81 }
82
83 for _, tt := range tests {
84 t.Run(tt.name, func(t *testing.T) {
85 if got := ansi.ITerm2(tt.data); got != tt.want {
86 t.Errorf("ITerm2() = %v, want %v", got, tt.want)
87 }
88 })
89 }
90 }