mirror of
https://github.com/golang/go
synced 2024-11-27 04:11:22 -07:00
Fix some naming consistency; make TestLoopCount use subtests
This commit is contained in:
parent
9c51c7d3a7
commit
249744f0e2
@ -318,17 +318,20 @@ func TestTransparentPixelOutsidePaletteRange(t *testing.T) {
|
||||
}
|
||||
|
||||
func TestLoopCount(t *testing.T) {
|
||||
tests := []struct {
|
||||
testCases := []struct {
|
||||
name string
|
||||
data []byte
|
||||
loopCount int
|
||||
}{
|
||||
{
|
||||
"loopcount-missing",
|
||||
[]byte("GIF89a000\x00000" +
|
||||
",0\x00\x00\x00\n\x00\n\x00\x80000000" + // image 0 descriptor & color table
|
||||
"\x02\b\xf01u\xb9\xfdal\x05\x00;"), // image 0 image data & trailer
|
||||
-1,
|
||||
},
|
||||
{
|
||||
"loopcount-0",
|
||||
[]byte("GIF89a000\x00000" +
|
||||
"!\xff\vNETSCAPE2.0\x03\x01\x00\x00\x00" + // loop count = 0
|
||||
",0\x00\x00\x00\n\x00\n\x00\x80000000" + // image 0 descriptor & color table
|
||||
@ -338,6 +341,7 @@ func TestLoopCount(t *testing.T) {
|
||||
0,
|
||||
},
|
||||
{
|
||||
"loopcount-1",
|
||||
[]byte("GIF89a000\x00000" +
|
||||
"!\xff\vNETSCAPE2.0\x03\x01\x01\x00\x00" + // loop count = 1
|
||||
",0\x00\x00\x00\n\x00\n\x00\x80000000" + // image 0 descriptor & color table
|
||||
@ -348,26 +352,28 @@ func TestLoopCount(t *testing.T) {
|
||||
},
|
||||
}
|
||||
|
||||
for _, tt := range tests {
|
||||
img, err := DecodeAll(bytes.NewReader(tt.data))
|
||||
if err != nil {
|
||||
t.Fatal("DecodeAll:", err)
|
||||
}
|
||||
w := new(bytes.Buffer)
|
||||
err = EncodeAll(w, img)
|
||||
if err != nil {
|
||||
t.Fatal("EncodeAll:", err)
|
||||
}
|
||||
img1, err := DecodeAll(w)
|
||||
if err != nil {
|
||||
t.Fatal("DecodeAll:", err)
|
||||
}
|
||||
if img.LoopCount != tt.loopCount {
|
||||
t.Errorf("loop count mismatch: %d vs %d", img.LoopCount, tt.loopCount)
|
||||
}
|
||||
if img.LoopCount != img1.LoopCount {
|
||||
t.Errorf("loop count failed round-trip: %d vs %d", img.LoopCount, img1.LoopCount)
|
||||
}
|
||||
for _, tc := range testCases {
|
||||
t.Run(tc.name, func(t *testing.T) {
|
||||
img, err := DecodeAll(bytes.NewReader(tc.data))
|
||||
if err != nil {
|
||||
t.Fatal("DecodeAll:", err)
|
||||
}
|
||||
w := new(bytes.Buffer)
|
||||
err = EncodeAll(w, img)
|
||||
if err != nil {
|
||||
t.Fatal("EncodeAll:", err)
|
||||
}
|
||||
img1, err := DecodeAll(w)
|
||||
if err != nil {
|
||||
t.Fatal("DecodeAll:", err)
|
||||
}
|
||||
if img.LoopCount != tc.loopCount {
|
||||
t.Errorf("loop count mismatch: %d vs %d", img.LoopCount, tc.loopCount)
|
||||
}
|
||||
if img.LoopCount != img1.LoopCount {
|
||||
t.Errorf("loop count failed round-trip: %d vs %d", img.LoopCount, img1.LoopCount)
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user