|
@@ -1,7 +1,12 @@
|
|
|
package excelize
|
|
package excelize
|
|
|
|
|
|
|
|
import (
|
|
import (
|
|
|
|
|
+ "bufio"
|
|
|
|
|
+ "bytes"
|
|
|
|
|
+ "strings"
|
|
|
"testing"
|
|
"testing"
|
|
|
|
|
+
|
|
|
|
|
+ "github.com/stretchr/testify/assert"
|
|
|
)
|
|
)
|
|
|
|
|
|
|
|
func BenchmarkWrite(b *testing.B) {
|
|
func BenchmarkWrite(b *testing.B) {
|
|
@@ -26,3 +31,18 @@ func BenchmarkWrite(b *testing.B) {
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+func TestWriteTo(t *testing.T) {
|
|
|
|
|
+ f := File{}
|
|
|
|
|
+ buf := bytes.Buffer{}
|
|
|
|
|
+ f.XLSX = make(map[string][]byte, 0)
|
|
|
|
|
+ f.XLSX["/d/"] = []byte("s")
|
|
|
|
|
+ _, err := f.WriteTo(bufio.NewWriter(&buf))
|
|
|
|
|
+ assert.EqualError(t, err, "zip: write to directory")
|
|
|
|
|
+ delete(f.XLSX, "/d/")
|
|
|
|
|
+ // Test file path overflow
|
|
|
|
|
+ const maxUint16 = 1<<16 - 1
|
|
|
|
|
+ f.XLSX[strings.Repeat("s", maxUint16+1)] = nil
|
|
|
|
|
+ _, err = f.WriteTo(bufio.NewWriter(&buf))
|
|
|
|
|
+ assert.EqualError(t, err, "zip: FileHeader.Name too long")
|
|
|
|
|
+}
|