comment_test.go 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of
  2. // this source code is governed by a BSD-style license that can be found in
  3. // the LICENSE file.
  4. //
  5. // Package excelize providing a set of functions that allow you to write to
  6. // and read from XLSX files. Support reads and writes XLSX file generated by
  7. // Microsoft Excel™ 2007 and later. Support save file without losing original
  8. // charts of XLSX. This library needs Go version 1.10 or later.
  9. package excelize
  10. import (
  11. "path/filepath"
  12. "strings"
  13. "testing"
  14. "github.com/stretchr/testify/assert"
  15. )
  16. func TestAddComments(t *testing.T) {
  17. f, err := prepareTestBook1()
  18. if !assert.NoError(t, err) {
  19. t.FailNow()
  20. }
  21. s := strings.Repeat("c", 32768)
  22. assert.NoError(t, f.AddComment("Sheet1", "A30", `{"author":"`+s+`","text":"`+s+`"}`))
  23. assert.NoError(t, f.AddComment("Sheet2", "B7", `{"author":"Excelize: ","text":"This is a comment."}`))
  24. // Test add comment on not exists worksheet.
  25. assert.EqualError(t, f.AddComment("SheetN", "B7", `{"author":"Excelize: ","text":"This is a comment."}`), "sheet SheetN is not exist")
  26. if assert.NoError(t, f.SaveAs(filepath.Join("test", "TestAddComments.xlsx"))) {
  27. assert.Len(t, f.GetComments(), 2)
  28. }
  29. }
  30. func TestDecodeVMLDrawingReader(t *testing.T) {
  31. f := NewFile()
  32. path := "xl/drawings/vmlDrawing1.xml"
  33. f.XLSX[path] = MacintoshCyrillicCharset
  34. f.decodeVMLDrawingReader(path)
  35. }
  36. func TestCommentsReader(t *testing.T) {
  37. f := NewFile()
  38. path := "xl/comments1.xml"
  39. f.XLSX[path] = MacintoshCyrillicCharset
  40. f.commentsReader(path)
  41. }
  42. func TestCountComments(t *testing.T) {
  43. f := NewFile()
  44. f.Comments["xl/comments1.xml"] = nil
  45. assert.Equal(t, f.countComments(), 1)
  46. }