Debian Codegraph @

ansi/iterm2/file_test.go

raw
1 package iterm2
2
3 import (
4 "encoding/base64"
5 "testing"
6 )
7
8 func TestCells(t *testing.T) {
9 tests := []struct {
10 input int
11 want string
12 }{
13 {0, "0"},
14 {10, "10"},
15 {-5, "-5"},
16 {100, "100"},
17 }
18
19 for _, tt := range tests {
20 t.Run(tt.want, func(t *testing.T) {
21 if got := Cells(tt.input); got != tt.want {
22 t.Errorf("Cells(%d) = %v, want %v", tt.input, got, tt.want)
23 }
24 })
25 }
26 }
27
28 func TestPixels(t *testing.T) {
29 tests := []struct {
30 input int
31 want string
32 }{
33 {0, "0px"},
34 {10, "10px"},
35 {-5, "-5px"},
36 {100, "100px"},
37 }
38
39 for _, tt := range tests {
40 t.Run(tt.want, func(t *testing.T) {
41 if got := Pixels(tt.input); got != tt.want {
42 t.Errorf("Pixels(%d) = %v, want %v", tt.input, got, tt.want)
43 }
44 })
45 }
46 }
47
48 func TestPercent(t *testing.T) {
49 tests := []struct {
50 input int
51 want string
52 }{
53 {0, "0%"},
54 {10, "10%"},
55 {-5, "-5%"},
56 {100, "100%"},
57 }
58
59 for _, tt := range tests {
60 t.Run(tt.want, func(t *testing.T) {
61 if got := Percent(tt.input); got != tt.want {
62 t.Errorf("Percent(%d) = %v, want %v", tt.input, got, tt.want)
63 }
64 })
65 }
66 }
67
68 func TestFile_String(t *testing.T) {
69 sampleContent := []byte("test-content")
70 tests := []struct {
71 name string
72 file file
73 want string
74 }{
75 {
76 name: "empty file",
77 file: file{},
78 want: "",
79 },
80 {
81 name: "basic file",
82 file: file{
83 Name: "test.png",
84 Size: 1024,
85 },
86 want: "name=test.png;size=1024",
87 },
88 {
89 name: "file with dimensions",
90 file: file{
91 Name: "test.png",
92 Width: "100px",
93 Height: "auto",
94 },
95 want: "name=test.png;width=100px;height=auto",
96 },
97 {
98 name: "file with all options",
99 file: file{
100 Name: "test.png",
101 Size: 1024,
102 Width: "100px",
103 Height: "50%",
104 IgnoreAspectRatio: true,
105 Inline: true,
106 DoNotMoveCursor: true,
107 Content: sampleContent,
108 },
109 want: "name=test.png;size=1024;width=100px;height=50%;preserveAspectRatio=0;inline=1;doNotMoveCursor=1",
110 },
111 }
112
113 for _, tt := range tests {
114 t.Run(tt.name, func(t *testing.T) {
115 if got := tt.file.String(); got != tt.want {
116 t.Errorf("file.String() = %v, want %v", got, tt.want)
117 }
118 })
119 }
120 }
121
122 func TestFile_String_WithContent(t *testing.T) {
123 sampleContent := []byte("test-content")
124 encodedContent := base64.StdEncoding.EncodeToString(sampleContent)
125
126 f := File{
127 Name: "test.png",
128 Content: []byte(encodedContent),
129 }
130
131 want := "File=name=test.png:" + encodedContent
132 if got := f.String(); got != want {
133 t.Errorf("File.String() = %v, want %v", got, want)
134 }
135 }
136
137 func TestMultipartFile_String(t *testing.T) {
138 f := MultipartFile{
139 Name: "test.png",
140 Size: 1024,
141 Width: "100px",
142 Height: "50%",
143 }
144
145 want := "MultipartFile=name=test.png;size=1024;width=100px;height=50%"
146 if got := f.String(); got != want {
147 t.Errorf("MultipartFile.String() = %v, want %v", got, want)
148 }
149 }
150
151 func TestFilePart_String(t *testing.T) {
152 sampleContent := []byte("test-content")
153 f := FilePart{
154 Content: sampleContent,
155 }
156
157 want := "FilePart=" + string(sampleContent)
158 if got := f.String(); got != want {
159 t.Errorf("FilePart.String() = %v, want %v", got, want)
160 }
161 }
162
163 func TestFileEnd_String(t *testing.T) {
164 f := FileEnd{}
165 want := "FileEnd"
166 if got := f.String(); got != want {
167 t.Errorf("FileEnd.String() = %v, want %v", got, want)
168 }
169 }
170
171 func TestAuto_Constant(t *testing.T) {
172 if Auto != "auto" {
173 t.Errorf("Auto constant = %v, want 'auto'", Auto)
174 }
175 }