diff options
| author | xuri <xuri.me@gmail.com> | 2020-05-22 16:53:46 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-05-22 16:53:46 +0800 |
| commit | ec14de32f0c06f7a26b6b79578f666c0cc50b72c (patch) | |
| tree | c6ebd61a7d9a7da5b993ffb82e4fb6c036e75d6a /file_test.go | |
| parent | aa7eadbffe6ae2f9f86201bbaaa4c1d1e8829cae (diff) | |
| parent | 2efc7107ff30dc7f1e1a798082616ee488f99489 (diff) | |
Merge branch 'master' into fix/cell_lock
Diffstat (limited to 'file_test.go')
| -rw-r--r-- | file_test.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/file_test.go b/file_test.go new file mode 100644 index 0000000..e27b754 --- /dev/null +++ b/file_test.go @@ -0,0 +1,48 @@ +package excelize + +import ( + "bufio" + "bytes" + "strings" + "testing" + + "github.com/stretchr/testify/assert" +) + +func BenchmarkWrite(b *testing.B) { + const s = "This is test data" + for i := 0; i < b.N; i++ { + f := NewFile() + for row := 1; row <= 10000; row++ { + for col := 1; col <= 20; col++ { + val, err := CoordinatesToCellName(col, row) + if err != nil { + b.Error(err) + } + if err := f.SetCellDefault("Sheet1", val, s); err != nil { + b.Error(err) + } + } + } + // Save xlsx file by the given path. + err := f.SaveAs("./test.xlsx") + if err != nil { + b.Error(err) + } + } +} + +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") +} |
