adjust_test.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  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. &xlsxMergeCell{
  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. &xlsxMergeCell{
  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.Sheet["xl/worksheets/sheet1.xml"] = &xlsxWorksheet{
  45. MergeCells: &xlsxMergeCells{
  46. Cells: []*xlsxMergeCell{
  47. &xlsxMergeCell{
  48. Ref: "A:B1",
  49. },
  50. },
  51. },
  52. }
  53. f.Sheet["xl/worksheets/sheet2.xml"] = &xlsxWorksheet{
  54. AutoFilter: &xlsxAutoFilter{
  55. Ref: "A1:B",
  56. },
  57. }
  58. // testing adjustHelper with illegal cell coordinates.
  59. assert.EqualError(t, f.adjustHelper("sheet1", rows, 0, 0), `cannot convert cell "A" to coordinates: invalid cell name "A"`)
  60. assert.EqualError(t, f.adjustHelper("sheet2", rows, 0, 0), `cannot convert cell "B" to coordinates: invalid cell name "B"`)
  61. }