adjust_test.go 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  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. }
  65. func TestAdjustCalcChain(t *testing.T) {
  66. f := NewFile()
  67. f.CalcChain = &xlsxCalcChain{
  68. C: []xlsxCalcChainC{
  69. {R: "B2"},
  70. },
  71. }
  72. assert.NoError(t, f.InsertCol("Sheet1", "A"))
  73. assert.NoError(t, f.InsertRow("Sheet1", 1))
  74. f.CalcChain.C[0].R = "invalid coordinates"
  75. assert.EqualError(t, f.InsertCol("Sheet1", "A"), `cannot convert cell "invalid coordinates" to coordinates: invalid cell name "invalid coordinates"`)
  76. f.CalcChain = nil
  77. assert.NoError(t, f.InsertCol("Sheet1", "A"))
  78. }