Debian Codegraph @

misc_test.go

raw
1 package main
2
3 import (
4 "math"
5 "os"
6 "reflect"
7 "strings"
8 "testing"
9 "time"
10 )
11
12 func TestIsRoot(t *testing.T) {
13 sep := string(os.PathSeparator)
14 if !isRoot(sep) {
15 t.Errorf(`"%s" is root`, sep)
16 }
17
18 paths := []string{
19 "",
20 "~",
21 "foo",
22 "foo/bar",
23 "foo/bar",
24 "/home",
25 "/home/user",
26 }
27
28 for _, p := range paths {
29 if isRoot(p) {
30 t.Errorf("'%s' is not root", p)
31 }
32 }
33 }
34
35 func TestFirstGraphemeCluster(t *testing.T) {
36 tests := []struct {
37 s string
38 exp string
39 }{
40 {"", ""},
41 {"a", "a"},
42 {"世界", "世"},
43 {"🏳️a", "🏳️"},
44 }
45
46 for _, test := range tests {
47 if got := firstGraphemeCluster(test.s); got != test.exp {
48 t.Errorf("at input '%v' expected '%v' but got '%v'", test.s, test.exp, got)
49 }
50 }
51 }
52
53 func TestLastGraphemeCluster(t *testing.T) {
54 tests := []struct {
55 s string
56 exp string
57 }{
58 {"", ""},
59 {"a", "a"},
60 {"世界", "界"},
61 {"a🏳️", "🏳️"},
62 }
63
64 for _, test := range tests {
65 if got := lastGraphemeCluster(test.s); got != test.exp {
66 t.Errorf("at input '%v' expected '%v' but got '%v'", test.s, test.exp, got)
67 }
68 }
69 }
70
71 func TestTruncateRight(t *testing.T) {
72 tests := []struct {
73 s string
74 maxWidth int
75 exp string
76 }{
77 {"", 0, ""},
78 {"", 1, ""},
79 {"a", 0, ""},
80 {"a", 1, "a"},
81 {"ab", 1, "a"},
82 {"世", 0, ""},
83 {"世", 1, ""},
84 {"世界", 2, "世"},
85 {"世界", 3, "世"},
86 {"a🏳️b", 2, "a"},
87 {"a🏳️b", 3, "a🏳️"},
88 {"a🏳️b", 4, "a🏳️b"},
89 }
90
91 for _, test := range tests {
92 if got := truncateRight(test.s, test.maxWidth); got != test.exp {
93 t.Errorf("at input ('%v', %v) expected '%v' but got '%v'", test.s, test.maxWidth, test.exp, got)
94 }
95 }
96 }
97
98 func TestTruncateLeft(t *testing.T) {
99 tests := []struct {
100 s string
101 maxWidth int
102 exp string
103 }{
104 {"", 0, ""},
105 {"", 1, ""},
106 {"a", 0, ""},
107 {"a", 1, "a"},
108 {"ab", 1, "b"},
109 {"世", 0, ""},
110 {"世", 1, ""},
111 {"世界", 2, "界"},
112 {"世界", 3, "界"},
113 {"a🏳️b", 2, "b"},
114 {"a🏳️b", 3, "🏳️b"},
115 {"a🏳️b", 4, "a🏳️b"},
116 }
117
118 for _, test := range tests {
119 if got := truncateLeft(test.s, test.maxWidth); got != test.exp {
120 t.Errorf("at input ('%v', %v) expected '%v' but got '%v'", test.s, test.maxWidth, test.exp, got)
121 }
122 }
123 }
124
125 func TestCmdEscape(t *testing.T) {
126 tests := []struct {
127 s string
128 exp string
129 }{
130 {"", ""},
131 {"foo", "foo"},
132 {"foo bar", `foo\ bar`},
133 {"foo bar", `foo\ \ bar`},
134 {`foo\bar`, `foo\\bar`},
135 {`foo\ bar`, `foo\\\ bar`},
136 {`foo;bar`, `foo\;bar`},
137 {`foo#bar`, `foo\#bar`},
138 {`foo\tbar`, `foo\\tbar`},
139 {"foo\tbar", "foo\\\tbar"},
140 {`foo\`, `foo\\`},
141 }
142
143 for _, test := range tests {
144 if got := cmdEscape(test.s); !reflect.DeepEqual(got, test.exp) {
145 t.Errorf("at input '%v' expected '%v' but got '%v'", test.s, test.exp, got)
146 }
147 }
148 }
149
150 func TestCmdUnescape(t *testing.T) {
151 tests := []struct {
152 s string
153 exp string
154 }{
155 {"", ""},
156 {"foo", "foo"},
157 {`foo\ bar`, "foo bar"},
158 {`foo\ \ bar`, "foo bar"},
159 {`foo\\bar`, `foo\bar`},
160 {`foo\\\ bar`, `foo\ bar`},
161 {`foo\;bar`, `foo;bar`},
162 {`foo\#bar`, `foo#bar`},
163 {`foo\\tbar`, `foo\tbar`},
164 {"foo\\\tbar", "foo\tbar"},
165 {`foo\`, `foo\`},
166 }
167
168 for _, test := range tests {
169 if got := cmdUnescape(test.s); !reflect.DeepEqual(got, test.exp) {
170 t.Errorf("at input '%v' expected '%v' but got '%v'", test.s, test.exp, got)
171 }
172 }
173 }
174
175 func TestTokenize(t *testing.T) {
176 tests := []struct {
177 s string
178 exp []string
179 }{
180 {"", []string{""}},
181 {"foo", []string{"foo"}},
182 {`foo\`, []string{`foo\`}},
183 {`foo"`, []string{`foo"`}},
184 {"foo bar", []string{"foo", "bar"}},
185 {`foo\ bar`, []string{`foo\ bar`}},
186 {`"foo bar"`, []string{`"foo bar"`}},
187 {`"foo" "bar"`, []string{`"foo"`, `"bar"`}},
188 {`"foo "bar"`, []string{`"foo "bar"`}},
189 {`"foo\" bar"`, []string{`"foo\" bar"`}},
190 {`\"foo bar\"`, []string{`\"foo`, `bar\"`}},
191 {`:rename foo\ bar`, []string{":rename", `foo\ bar`}},
192 {`!dir "C:\Program Files"`, []string{"!dir", `"C:\Program Files"`}},
193 }
194
195 for _, test := range tests {
196 if got := tokenize(test.s); !reflect.DeepEqual(got, test.exp) {
197 t.Errorf("at input '%v' expected '%v' but got '%v'", test.s, test.exp, got)
198 }
199 }
200 }
201
202 func TestSplitWord(t *testing.T) {
203 tests := []struct {
204 s string
205 word string
206 rest string
207 }{
208 {"", "", ""},
209 {"foo", "foo", ""},
210 {" foo", "foo", ""},
211 {"foo ", "foo", ""},
212 {" foo ", "foo", ""},
213 {"foo bar baz", "foo", "bar baz"},
214 {" foo bar baz", "foo", "bar baz"},
215 {"foo bar baz", "foo", "bar baz"},
216 {" foo bar baz", "foo", "bar baz"},
217 }
218
219 for _, test := range tests {
220 if w, r := splitWord(test.s); w != test.word || r != test.rest {
221 t.Errorf("at input '%s' expected '%s' and '%s' but got '%s' and '%s'", test.s, test.word, test.rest, w, r)
222 }
223 }
224 }
225
226 func TestReadArrays(t *testing.T) {
227 tests := []struct {
228 s string
229 minCols int
230 maxCols int
231 exp [][]string
232 }{
233 {"foo bar", 2, 2, [][]string{{"foo", "bar"}}},
234 {"foo bar ", 2, 2, [][]string{{"foo", "bar"}}},
235 {" foo bar", 2, 2, [][]string{{"foo", "bar"}}},
236 {" foo bar ", 2, 2, [][]string{{"foo", "bar"}}},
237 {"foo bar#baz", 2, 2, [][]string{{"foo", "bar"}}},
238 {"foo bar #baz", 2, 2, [][]string{{"foo", "bar"}}},
239 {`'foo#baz' bar`, 2, 2, [][]string{{"foo#baz", "bar"}}},
240 {`"foo#baz" bar`, 2, 2, [][]string{{"foo#baz", "bar"}}},
241 {"foo bar baz", 3, 3, [][]string{{"foo", "bar", "baz"}}},
242 {`"foo bar baz"`, 1, 1, [][]string{{"foo bar baz"}}},
243 }
244
245 for _, test := range tests {
246 if got, _ := readArrays(strings.NewReader(test.s), test.minCols, test.maxCols); !reflect.DeepEqual(got, test.exp) {
247 t.Errorf("at input '%v' expected '%v' but got '%v'", test.s, test.exp, got)
248 }
249 }
250 }
251
252 func TestHumanize(t *testing.T) {
253 tests := []struct {
254 size int64
255 expected string
256 }{
257 {0, "0B"},
258 {1, "1B"},
259 {2, "2B"},
260 {10, "10B"},
261 {100, "100B"},
262 {1000, "1000B"},
263 {1023, "1023B"},
264 {1024, "1.0K"},
265 {1025, "1.0K"}, // 1.000976563 KiB
266 {10188, "9.9K"}, // 9.94921875 KiB
267 {10189, "10.0K"}, // 9.950195313 KiB
268 {10240, "10.0K"}, // 10 KiB
269 {10291, "10.0K"}, // 10.049804688 KiB
270 {10292, "10.1K"}, // 10.05078125 KiB
271 {10342, "10.1K"}, // 10.099609375 KiB
272 {102348, "99.9K"}, // 99.94921875 KiB
273 {102349, "100K"}, // 99.950195313 KiB
274 {1023487, "999K"}, // 999.499023438 KiB
275 {1023488, "1000K"}, // 999.5 KiB
276 {1048063, "1023K"}, // 1023.499023438 KiB
277 {1048064, "1.0M"}, // 1023.5 KiB
278 {1072693248, "1023M"}, // 1023 MiB
279 {1073217535, "1023M"}, // 1023.499999046 MiB
280 {1073217536, "1.0G"}, // 1023.5 MiB
281 {1073741824, "1.0G"}, // 1 GiB
282 {1610612736, "1.5G"}, // 1.5 GiB
283 {1319413953332, "1.2T"}, // 1.2 TiB
284 {1463669878895412, "1.3P"}, // 1.3 PiB
285 {7955158381787244544, "6.9E"}, // 6.9 EiB
286 {math.MaxInt64, "8.0E"}, // 8 EiB
287 }
288
289 gOpts.sizeunits = "binary"
290 for _, test := range tests {
291 if got := humanize(test.size); got != test.expected {
292 t.Errorf("at input ('%d', '%s') expected '%s' but got '%s'", test.size, gOpts.sizeunits, test.expected, got)
293 }
294 }
295
296 tests = []struct {
297 size int64
298 expected string
299 }{
300 {0, "0B"},
301 {1, "1B"},
302 {2, "2B"},
303 {10, "10B"},
304 {100, "100B"},
305 {999, "999B"},
306 {1000, "1.0K"},
307 {1001, "1.0K"},
308 {1049, "1.0K"},
309 {1050, "1.1K"},
310 {1051, "1.1K"},
311 {9949, "9.9K"},
312 {9950, "10.0K"},
313 {9951, "10.0K"},
314 {9999, "10.0K"},
315 {10000, "10.0K"},
316 {10001, "10.0K"},
317 {99949, "99.9K"},
318 {99950, "100K"},
319 {99951, "100K"},
320 {999499, "999K"},
321 {999500, "1.0M"},
322 {999501, "1.0M"},
323 {999999, "1.0M"},
324 {1000000, "1.0M"},
325 {1000001, "1.0M"},
326 {999499999, "999M"},
327 {999500000, "1.0G"},
328 {999500001, "1.0G"},
329 {999999999, "1.0G"},
330 {1000000000, "1.0G"},
331 {1000000001, "1.0G"},
332 {math.MaxInt64, "9.2E"},
333 }
334
335 gOpts.sizeunits = "decimal"
336 for _, test := range tests {
337 if got := humanize(test.size); got != test.expected {
338 t.Errorf("at input ('%d', '%s') expected '%s' but got '%s'", test.size, gOpts.sizeunits, test.expected, got)
339 }
340 }
341 }
342
343 func TestPermString(t *testing.T) {
344 tests := []struct {
345 name string
346 m os.FileMode
347 exp string
348 }{
349 {"none", 0, "----------"},
350 {"regular file", 0o644, "-rw-r--r--"},
351 {"executable", 0o755, "-rwxr-xr-x"},
352 {"directory", 0o755 | os.ModeDir, "drwxr-xr-x"},
353 {"symbolic link", 0o777 | os.ModeSymlink, "lrwxrwxrwx"},
354 {"named pipe", 0o644 | os.ModeNamedPipe, "prw-r--r--"},
355 {"socket", 0o777 | os.ModeSocket, "srwxrwxrwx"},
356 {"character device", 0o660 | os.ModeCharDevice, "crw-rw----"},
357 {"block device", 0o660 | os.ModeDevice, "brw-rw----"},
358 {"setuid", 0o644 | os.ModeSetuid, "-rwSr--r--"},
359 {"setuid executable", 0o755 | os.ModeSetuid, "-rwsr-xr-x"},
360 {"setgid", 0o644 | os.ModeSetgid, "-rw-r-Sr--"},
361 {"setgid executable", 0o755 | os.ModeSetgid, "-rwxr-sr-x"},
362 {"sticky", 0o644 | os.ModeSticky, "-rw-r--r-T"},
363 {"sticky executable", 0o755 | os.ModeSticky, "-rwxr-xr-t"},
364 {"sticky directory", 0o777 | os.ModeDir | os.ModeSticky, "drwxrwxrwt"},
365 }
366
367 for _, test := range tests {
368 t.Run(test.name, func(t *testing.T) {
369 if got := permString(test.m); got != test.exp {
370 t.Errorf("at input '%#o' expected '%s' but got '%s'", test.m, test.exp, got)
371 }
372 })
373 }
374 }
375
376 func TestNaturalCmp(t *testing.T) {
377 tests := []struct {
378 s1 string
379 s2 string
380 exp int
381 }{
382 {"", "", 0},
383 {"a", "a", 0},
384 {"", "a", -1},
385 {"a", "b", -1},
386 {"a", "ab", -1},
387 {"0", "0", 0},
388 {"0", "00", -1},
389 {"1", "1", 0},
390 {"1", "01", -1},
391 {"2", "10", -1},
392 {"123", "foo", -1},
393 {"foo", "foo1", -1},
394 {"foo1", "foobar", -1},
395 {"foo1", "foobar1", -1},
396 {"foo2", "foo10", -1},
397 {"foo2bar", "foo10bar", -1},
398 {"foo0", "foo00", -1},
399 {"foo0bar", "foo00bar", -1},
400 {"foo1", "foo01", -1},
401 {"foo1bar", "foo01bar", -1},
402 }
403
404 for _, test := range tests {
405 if got := naturalCmp(test.s1, test.s2); got != test.exp {
406 t.Errorf("at input '%s' and '%s' expected '%d' but got '%d'", test.s1, test.s2, test.exp, got)
407 }
408
409 if got := naturalCmp(test.s2, test.s1); got != -test.exp {
410 t.Errorf("at input '%s' and '%s' expected '%d' but got '%d'", test.s2, test.s1, -test.exp, got)
411 }
412 }
413 }
414
415 type fakeFileInfo struct {
416 name string
417 isDir bool
418 }
419
420 func (fileinfo fakeFileInfo) Name() string { return fileinfo.name }
421 func (fileinfo fakeFileInfo) Size() int64 { return 0 }
422 func (fileinfo fakeFileInfo) Mode() os.FileMode { return os.FileMode(0o000) }
423 func (fileinfo fakeFileInfo) ModTime() time.Time { return time.Unix(0, 0) }
424 func (fileinfo fakeFileInfo) IsDir() bool { return fileinfo.isDir }
425 func (fileinfo fakeFileInfo) Sys() any { return nil }
426
427 func TestGetFileExtension(t *testing.T) {
428 tests := []struct {
429 name string
430 fileName string
431 isDir bool
432 expectedExtension string
433 }{
434 {"normal file", "file.txt", false, ".txt"},
435 {"file without extension", "file", false, ""},
436 {"hidden file", ".gitignore", false, ""},
437 {"hidden file with extension", ".file.txt", false, ".txt"},
438 {"directory", "dir", true, ""},
439 {"hidden directory", ".git", true, ""},
440 {"directory with dot", "profile.d", true, ""},
441 }
442
443 for _, test := range tests {
444 t.Run(test.name, func(t *testing.T) {
445 if got := getFileExtension(fakeFileInfo{test.fileName, test.isDir}); got != test.expectedExtension {
446 t.Errorf("at input '%s' expected '%s' but got '%s'", test.fileName, test.expectedExtension, got)
447 }
448 })
449 }
450 }
451
452 func TestTruncateFilename(t *testing.T) {
453 tests := []struct {
454 file fakeFileInfo
455 maxWidth int
456 truncatePct int
457 exp string
458 }{
459 {fakeFileInfo{"foo", false}, 0, 0, ""},
460 {fakeFileInfo{"foo", false}, 0, 100, ""},
461 {fakeFileInfo{"foo", false}, 1, 0, "~"},
462 {fakeFileInfo{"foo", false}, 1, 100, "~"},
463 {fakeFileInfo{"foo", false}, 2, 0, "~o"},
464 {fakeFileInfo{"foo", false}, 2, 100, "f~"},
465 {fakeFileInfo{"foo", false}, 3, 0, "foo"},
466 {fakeFileInfo{"foo", false}, 3, 100, "foo"},
467 {fakeFileInfo{"foo", false}, 4, 0, "foo"},
468 {fakeFileInfo{"foo", false}, 4, 100, "foo"},
469 {fakeFileInfo{"foo.txt", false}, 0, 0, ""},
470 {fakeFileInfo{"foo.txt", false}, 0, 100, ""},
471 {fakeFileInfo{"foo.txt", false}, 1, 0, "~"},
472 {fakeFileInfo{"foo.txt", false}, 1, 100, "~"},
473 {fakeFileInfo{"foo.txt", false}, 2, 0, "~."},
474 {fakeFileInfo{"foo.txt", false}, 2, 100, "~."},
475 {fakeFileInfo{"foo.txt", false}, 3, 0, "~.t"},
476 {fakeFileInfo{"foo.txt", false}, 3, 100, "~.t"},
477 {fakeFileInfo{"foo.txt", false}, 4, 0, "~.tx"},
478 {fakeFileInfo{"foo.txt", false}, 4, 100, "~.tx"},
479 {fakeFileInfo{"foo.txt", false}, 5, 0, "~.txt"},
480 {fakeFileInfo{"foo.txt", false}, 5, 100, "~.txt"},
481 {fakeFileInfo{"foo.txt", false}, 6, 0, "~o.txt"},
482 {fakeFileInfo{"foo.txt", false}, 6, 100, "f~.txt"},
483 {fakeFileInfo{"foobarbaz", false}, 7, 0, "~barbaz"},
484 {fakeFileInfo{"foobarbaz", false}, 7, 50, "foo~baz"},
485 {fakeFileInfo{"foobarbaz", false}, 7, 100, "foobar~"},
486 {fakeFileInfo{"foobarbaz.txt", false}, 11, 0, "~barbaz.txt"},
487 {fakeFileInfo{"foobarbaz.txt", false}, 11, 50, "foo~baz.txt"},
488 {fakeFileInfo{"foobarbaz.txt", false}, 11, 100, "foobar~.txt"},
489 {fakeFileInfo{"foobarbaz.d", true}, 9, 0, "~barbaz.d"},
490 {fakeFileInfo{"foobarbaz.d", true}, 9, 50, "foob~az.d"},
491 {fakeFileInfo{"foobarbaz.d", true}, 9, 100, "foobarba~"},
492 {fakeFileInfo{"世界世界.txt", false}, 10, 0, "~世界.txt"},
493 {fakeFileInfo{"世界世界.txt", false}, 10, 50, "世~界.txt"},
494 {fakeFileInfo{"世界世界.txt", false}, 10, 100, "世界~.txt"},
495 {fakeFileInfo{"世界世界.txt", false}, 11, 0, "~界世界.txt"},
496 {fakeFileInfo{"世界世界.txt", false}, 11, 50, "世~世界.txt"},
497 {fakeFileInfo{"世界世界.txt", false}, 11, 100, "世界世~.txt"},
498 }
499
500 for _, test := range tests {
501 if got := truncateFilename(test.file, test.maxWidth, test.truncatePct, "~"); got != test.exp {
502 t.Errorf("at input (%v, %v, %v) expected '%s' but got '%s'", test.file, test.maxWidth, test.truncatePct, test.exp, got)
503 }
504 }
505 }
506
507 func TestReadLines(t *testing.T) {
508 tests := []struct {
509 s string
510 maxLines int
511 lines []string
512 binary bool
513 sixel bool
514 }{
515 {"", 10, nil, false, false},
516 {"\r", 10, nil, false, false},
517 {"\r\n", 10, []string{""}, false, false},
518 {"\r\r\n", 10, []string{""}, false, false},
519 {"\n\n", 10, []string{"", ""}, false, false},
520 {"foo", 10, []string{"foo"}, false, false},
521 {"foo\n", 10, []string{"foo"}, false, false},
522 {"foo\r\n", 10, []string{"foo"}, false, false},
523 {"foo\nbar", 10, []string{"foo", "bar"}, false, false},
524 {"foo\nbar\n", 10, []string{"foo", "bar"}, false, false},
525 {"foo\r\nbar", 10, []string{"foo", "bar"}, false, false},
526 {"foo\r\nbar\r\n", 10, []string{"foo", "bar"}, false, false},
527 {"\033[31mfoo\033[0m", 10, []string{"\033[31mfoo\033[0m"}, false, false},
528 {"\000", 10, nil, true, false},
529 {"foo\r\n\000\r\nbar\r\n", 10, nil, true, false},
530 {"\033P\033\\", 10, []string{"\033P\033\\"}, false, true},
531 {"\033Pq\"1;1;1;1#0@\033\\", 10, []string{"\033Pq\"1;1;1;1#0@\033\\"}, false, true},
532 {"\033P\000\033\\", 10, []string{"\033\\"}, false, false},
533 {"\033P\n\033\\", 10, []string{"\033P\033\\"}, false, true},
534 {"\033P\r\n\033\\", 10, []string{"\033P\033\\"}, false, true},
535 {"\033P\033\\\033P\033\\", 10, []string{"\033P\033\\", "\033P\033\\"}, false, true},
536 {"foo\033P\033\\bar", 10, []string{"foo", "\033P\033\\", "bar"}, false, true},
537 {"foo\033P\033\\bar\033P\033\\baz", 10, []string{"foo", "\033P\033\\", "bar", "\033P\033\\", "baz"}, false, true},
538 {"foo\nbar\nbaz", 2, []string{"foo", "bar"}, false, false},
539 {"foo\nbar\nbaz\n", 2, []string{"foo", "bar"}, false, false},
540 {"foo\nbar\033P\033\\", 2, []string{"foo", "bar"}, false, false},
541 {"foo\nbar\nbaz", 3, []string{"foo", "bar", "baz"}, false, false},
542 {"foo\nbar\nbaz\n", 3, []string{"foo", "bar", "baz"}, false, false},
543 {"foo\nbar\033P\033\\", 3, []string{"foo", "bar", "\033P\033\\"}, false, true},
544 // Inside the DCS body, ESC must be followed by '\\' (ST) for the
545 // frame to be accepted. Any other byte aborts, so an attacker
546 // cannot embed CSI/OSC/nested-DCS through the sixel path.
547 {"\033P\033]52;c;x\033\\", 10, []string{"52;c;x\033\\"}, false, false},
548 }
549
550 for _, test := range tests {
551 lines, binary, sixel := readLines(strings.NewReader(test.s), test.maxLines)
552 if !reflect.DeepEqual(lines, test.lines) || binary != test.binary || sixel != test.sixel {
553 t.Errorf(
554 "at input (%q, %v) expected (%#v, %v, %v) but got (%#v, %v, %v)",
555 test.s, test.maxLines,
556 test.lines, test.binary, test.sixel,
557 lines, binary, sixel,
558 )
559 }
560 }
561 }
562
563 func TestGetWidths(t *testing.T) {
564 tests := []struct {
565 wtot int
566 ratios []int
567 drawbox bool
568 borderstyle borderStyle
569 exp []int
570 }{
571 {0, []int{1}, false, borderBox, []int{0}},
572 {0, []int{1}, true, borderBox, []int{0}},
573 {0, []int{1, 3, 2}, false, borderBox, []int{0, 0, 0}},
574 {0, []int{1, 3, 2}, true, borderBox, []int{0, 0, 0}},
575
576 {14, []int{1, 3, 2}, false, borderBox, []int{2, 6, 4}},
577 {16, []int{1, 3, 2}, true, borderBox, []int{2, 6, 4}},
578
579 {16, []int{1, 3, 2}, true, borderSeparators, []int{2, 7, 5}},
580 {16, []int{1, 3, 2}, true, borderOutline, []int{2, 6, 4}},
581 {16, []int{1, 3, 2}, true, borderRoundOutline, []int{2, 6, 4}},
582 {16, []int{1, 3, 2}, true, borderRoundBox, []int{2, 6, 4}},
583
584 {23, []int{1, 3, 2, 4}, false, borderBox, []int{2, 6, 4, 8}}, // windows end at 2.0, 8.0, 12.0, 20.0 respectively
585 {24, []int{1, 3, 2, 4}, false, borderBox, []int{2, 6, 5, 8}}, // windows end at 2.1, 8.4, 12.6, 21.0 respectively
586 {25, []int{1, 3, 2, 4}, false, borderBox, []int{2, 7, 4, 9}}, // windows end at 2.2, 8.8, 13.2, 22.0 respectively
587 {26, []int{1, 3, 2, 4}, false, borderBox, []int{2, 7, 5, 9}}, // windows end at 2.3, 9.2, 13.8, 23.0 respectively
588 }
589
590 for _, test := range tests {
591 widths := getWidths(test.wtot, test.ratios, test.drawbox, test.borderstyle)
592 if !reflect.DeepEqual(widths, test.exp) {
593 t.Errorf("at input (%v, %v, %v, %v) expected %v but got %v", test.wtot, test.ratios, test.drawbox, test.borderstyle, test.exp, widths)
594 }
595 }
596 }