adjust_test.go 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. package excelize
  2. import (
  3. "testing"
  4. "github.com/stretchr/testify/assert"
  5. )
  6. func TestAdjustMergeCells(t *testing.T) {
  7. f := NewFile()
  8. // testing adjustAutoFilter with illegal cell coordinates.
  9. assert.EqualError(t, f.adjustMergeCells(&xlsxWorksheet{
  10. MergeCells: &xlsxMergeCells{
  11. Cells: []*xlsxMergeCell{
  12. {
  13. Ref: "A:B1",
  14. },
  15. },
  16. },
  17. }, rows, 0, 0), `cannot convert cell "A" to coordinates: invalid cell name "A"`)
  18. assert.EqualError(t, f.adjustMergeCells(&xlsxWorksheet{
  19. MergeCells: &xlsxMergeCells{
  20. Cells: []*xlsxMergeCell{
  21. {
  22. Ref: "A1:B",
  23. },
  24. },
  25. },
  26. }, rows, 0, 0), `cannot convert cell "B" to coordinates: invalid cell name "B"`)
  27. }
  28. func TestAdjustAutoFilter(t *testing.T) {
  29. f := NewFile()
  30. // testing adjustAutoFilter with illegal cell coordinates.
  31. assert.EqualError(t, f.adjustAutoFilter(&xlsxWorksheet{
  32. AutoFilter: &xlsxAutoFilter{
  33. Ref: "A:B1",
  34. },
  35. }, rows, 0, 0), `cannot convert cell "A" to coordinates: invalid cell name "A"`)
  36. assert.EqualError(t, f.adjustAutoFilter(&xlsxWorksheet{
  37. AutoFilter: &xlsxAutoFilter{
  38. Ref: "A1:B",
  39. },
  40. }, rows, 0, 0), `cannot convert cell "B" to coordinates: invalid cell name "B"`)
  41. }
  42. func TestAdjustHelper(t *testing.T) {
  43. f := NewFile()
  44. f.NewSheet("Sheet2")
  45. f.Sheet["xl/worksheets/sheet1.xml"] = &xlsxWorksheet{
  46. MergeCells: &xlsxMergeCells{
  47. Cells: []*xlsxMergeCell{
  48. {
  49. Ref: "A:B1",
  50. },
  51. },
  52. },
  53. }
  54. f.Sheet["xl/worksheets/sheet2.xml"] = &xlsxWorksheet{
  55. AutoFilter: &xlsxAutoFilter{
  56. Ref: "A1:B",
  57. },
  58. }
  59. // testing adjustHelper with illegal cell coordinates.
  60. assert.EqualError(t, f.adjustHelper("Sheet1", rows, 0, 0), `cannot convert cell "A" to coordinates: invalid cell name "A"`)
  61. assert.EqualError(t, f.adjustHelper("Sheet2", rows, 0, 0), `cannot convert cell "B" to coordinates: invalid cell name "B"`)
  62. // testing adjustHelper on not exists worksheet.
  63. assert.EqualError(t, f.adjustHelper("SheetN", rows, 0, 0), "sheet SheetN is not exist")
  64. }