Skip to content

Commit

Permalink
fixup! rework: stricter sixel checks and remove trimming
Browse files Browse the repository at this point in the history
  • Loading branch information
horriblename committed Aug 5, 2023
1 parent 47136cb commit a9312a4
Showing 1 changed file with 22 additions and 18 deletions.
40 changes: 22 additions & 18 deletions sixel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,45 +6,49 @@ import (
)

func TestSixelSize(t *testing.T) {
header := "\x1bP0;1;0q"
colors := "#0;2;97;10;50#1;2;10;50;75"
tests := []struct {
si string
hi int
succ bool
wo, ho int
}{
{
"\x1bP;;;q\"1;1;1;12#0;2;97;97;97#1;2;75;75;75#0B$#1{\x1b\\", 12,
true, 1, 6,
header + colors + "#0v!10~$#1!11~-!11~\x1b\\", 30,
true, 11, 12,
},
{
"\x1bP;;;q\"1;1;1;12#0;2;97;97;97#1;2;75;75;75#0B$#1{-#0o$#1N\x1b\\", 30,
true, 1, 12,
{ // Size reported in raster attributes do not limit actual size
header + `"1;1;1;6` + colors + "#0~~-#1~~-\x1b\\", 30,
true, 2, 12,
},
{
"\x1bP;;;q\"1;1;1;12#0;2;97;97;97#1;2;75;75;75#0B$#1{-#0o$#1N\x1b\\", 12,
{ // missing trailing '-' still reports correct height
header + colors + "#0~-~\x1b\\", 30,
true, 1, 12,
},
{
"\x1bP;;;q\"1;1;1;12#0;2;97;97;97#1;2;75;75;75#0B$#1{-#0o$#1N\x1b\\", 11,
{ // oversized image is rejected
header + colors + "#0~-~-\x1b\\", 11,
false, 0, 0,
},
{
"\x1bP;;;q\"1;1;1;12#0;2;97;97;97#1;2;75;75;75#0B$#1{-#0o$#1N-\x1b\\", 30,
true, 1, 12,
{ // repeat introducer
header + colors + "#0!120~-!100~-\x1b\\", 30,
true, 120, 12,
},
{
"\x1bP;;;q\"1;1;1;12#0;2;97;97;97#1;2;75;75;75#0B$#1{-#0o$#1N-\x1b\\", 12,
true, 1, 12,
{ // '$' carriage return
header + colors + "#0FFFF$#1ww-\x1b\\", 30,
true, 4, 6,
},
{
"\x1bP;;;q\"1;1;1;12#0;2;97;97;97#1;2;75;75;75#0B$#1{-#0o$#1N-\x1b\\", 11,
false, 0, 0,
{ // '$' carriage return
header + colors + "#0FF$#1wwww-\x1b\\", 30,
true, 4, 6,
},
}

for i, test := range tests {
reader := strings.NewReader(test.si)
w, h, err := sixelSize(reader, test.hi)
println(i, test.si)
println()

if !test.succ {
if err == nil {
Expand Down

0 comments on commit a9312a4

Please sign in to comment.