Skip to content

Commit 7f78464

Browse files
committed
add test for ReadZipReader, close qax-os#642
1 parent 82bb115 commit 7f78464

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

excelize_test.go

+16
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,22 @@ func TestOpenReader(t *testing.T) {
220220

221221
_, err = OpenReader(r)
222222
assert.EqualError(t, err, "unexpected EOF")
223+
224+
_, err = OpenReader(bytes.NewReader([]byte{
225+
0x50, 0x4b, 0x03, 0x04, 0x0a, 0x00, 0x09, 0x00, 0x63, 0x00, 0x47, 0xa3, 0xb6, 0x50, 0x00, 0x00,
226+
0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0b, 0x00, 0x70, 0x61,
227+
0x73, 0x73, 0x77, 0x6f, 0x72, 0x64, 0x01, 0x99, 0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00,
228+
0x00, 0x21, 0x06, 0x59, 0xc0, 0x12, 0xf3, 0x19, 0xc7, 0x51, 0xd1, 0xc9, 0x31, 0xcb, 0xcc, 0x8a,
229+
0xe1, 0x44, 0xe1, 0x56, 0x20, 0x24, 0x1f, 0xba, 0x09, 0xda, 0x53, 0xd5, 0xef, 0x50, 0x4b, 0x07,
230+
0x08, 0x00, 0x00, 0x00, 0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x50, 0x4b, 0x01,
231+
0x02, 0x1f, 0x00, 0x0a, 0x00, 0x09, 0x00, 0x63, 0x00, 0x47, 0xa3, 0xb6, 0x50, 0x00, 0x00, 0x00,
232+
0x00, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x08, 0x00, 0x0b, 0x00, 0x00, 0x00, 0x00,
233+
0x00, 0x00, 0x00, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x61, 0x73, 0x73, 0x77,
234+
0x6f, 0x72, 0x64, 0x01, 0x99, 0x07, 0x00, 0x02, 0x00, 0x41, 0x45, 0x03, 0x00, 0x00, 0x50, 0x4b,
235+
0x05, 0x06, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00, 0x01, 0x00, 0x41, 0x00, 0x00, 0x00, 0x5d, 0x00,
236+
0x00, 0x00, 0x00, 0x00,
237+
}))
238+
assert.EqualError(t, err, "zip: unsupported compression algorithm")
223239
}
224240

225241
func TestBrokenFile(t *testing.T) {

lib.go

+2-12
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ import (
1515
"container/list"
1616
"fmt"
1717
"io"
18-
"log"
1918
"strconv"
2019
"strings"
2120
"unsafe"
@@ -59,7 +58,6 @@ func (f *File) saveFileList(name string, content []byte) {
5958
func readFile(file *zip.File) ([]byte, error) {
6059
rc, err := file.Open()
6160
if err != nil {
62-
log.Println(err)
6361
return nil, err
6462
}
6563
dat := make([]byte, 0, file.FileInfo().Size())
@@ -176,11 +174,7 @@ func CellNameToCoordinates(cell string) (int, int, error) {
176174
}
177175

178176
col, err := ColumnNameToNumber(colname)
179-
if err != nil {
180-
return -1, -1, fmt.Errorf(msg, cell, err)
181-
}
182-
183-
return col, row, nil
177+
return col, row, err
184178
}
185179

186180
// CoordinatesToCellName converts [X, Y] coordinates to alpha-numeric cell
@@ -195,11 +189,7 @@ func CoordinatesToCellName(col, row int) (string, error) {
195189
return "", fmt.Errorf("invalid cell coordinates [%d, %d]", col, row)
196190
}
197191
colname, err := ColumnNumberToName(col)
198-
if err != nil {
199-
// Error should never happens here.
200-
return "", fmt.Errorf("invalid cell coordinates [%d, %d]: %v", col, row, err)
201-
}
202-
return fmt.Sprintf("%s%d", colname, row), nil
192+
return fmt.Sprintf("%s%d", colname, row), err
203193
}
204194

205195
// boolPtr returns a pointer to a bool with the given value.

lib_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,9 @@ func TestBytesReplace(t *testing.T) {
208208
s := []byte{0x01}
209209
assert.EqualValues(t, s, bytesReplace(s, []byte{}, []byte{}, 0))
210210
}
211+
212+
func TestStack(t *testing.T) {
213+
s := NewStack()
214+
assert.Equal(t, s.Peek(), nil)
215+
assert.Equal(t, s.Pop(), nil)
216+
}

0 commit comments

Comments
 (0)