Skip to content

Commit

Permalink
scanSize tests
Browse files Browse the repository at this point in the history
  • Loading branch information
CannibalVox committed Feb 1, 2025
1 parent ed43f81 commit d44fac5
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 1 deletion.
2 changes: 1 addition & 1 deletion ansi/sixel/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -447,7 +447,7 @@ func (d *Decoder) scanSize(data []byte) (int, int) {
//
// a ! is a RLE indicator, and we should add the numeral to the current width
var currentWidth int
var newBand bool
newBand := true
for {
b, err := buffer.ReadByte()
if err != nil {
Expand Down
46 changes: 46 additions & 0 deletions ansi/sixel/sixel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,52 @@ import (
"testing"
)

func TestScanSize(t *testing.T) {
testCases := map[string]struct {
data string
expectedWidth int
expectedHeight int
}{
"two lines": {
"~~~~~~-~~~~~~-", 6, 12,
},
"two lines no newline at end": {
"~~~~~~-~~~~~~", 6, 12,
},
"no pixels": {
"", 0, 0,
},
"smaller carriage returns": {
"~$~~$~~~$~~~~$~~~~~$~~~~~~", 6, 6,
},
"transparent": {
"??????", 6, 6,
},
"RLE": {
"??!20?", 22, 6,
},
"Colors": {
"#0;2;0;0;0~~~~~$#1;2;100;100;100;~~~~~~-#0~~~~~~-#1~~~~~~", 6, 18,
},
}

for testName, testCase := range testCases {
t.Run(testName, func(t *testing.T) {
decoder := &Decoder{}
width, height := decoder.scanSize([]byte(testCase.data))
if width != testCase.expectedWidth {
t.Errorf("expected width of %d, but received width of %d", testCase.expectedWidth, width)
return
}

if height != testCase.expectedHeight {
t.Errorf("expected height of %d, but received height of %d", testCase.expectedHeight, height)
return
}
})
}
}

func TestFullImage(t *testing.T) {
testCases := map[string]struct {
imageWidth int
Expand Down

0 comments on commit d44fac5

Please sign in to comment.