2019-12-22 00:02:09 +08:00
|
|
|
package excelize
|
|
|
|
|
2022-11-12 00:02:11 +08:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
)
|
2019-12-22 00:02:09 +08:00
|
|
|
|
|
|
|
func TestCalcChainReader(t *testing.T) {
|
|
|
|
f := NewFile()
|
2022-11-12 00:02:11 +08:00
|
|
|
// Test read calculation chain with unsupported charset.
|
2019-12-22 00:02:09 +08:00
|
|
|
f.CalcChain = nil
|
2022-01-09 00:20:42 +08:00
|
|
|
f.Pkg.Store(defaultXMLPathCalcChain, MacintoshCyrillicCharset)
|
2022-11-12 00:02:11 +08:00
|
|
|
_, err := f.calcChainReader()
|
|
|
|
assert.EqualError(t, err, "XML syntax error on line 1: invalid UTF-8")
|
2019-12-22 00:02:09 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
func TestDeleteCalcChain(t *testing.T) {
|
|
|
|
f := NewFile()
|
|
|
|
f.CalcChain = &xlsxCalcChain{C: []xlsxCalcChainC{}}
|
|
|
|
f.ContentTypes.Overrides = append(f.ContentTypes.Overrides, xlsxOverride{
|
|
|
|
PartName: "/xl/calcChain.xml",
|
|
|
|
})
|
2022-11-12 00:02:11 +08:00
|
|
|
assert.NoError(t, f.deleteCalcChain(1, "A1"))
|
|
|
|
|
|
|
|
f.CalcChain = nil
|
|
|
|
f.Pkg.Store(defaultXMLPathCalcChain, MacintoshCyrillicCharset)
|
|
|
|
assert.EqualError(t, f.deleteCalcChain(1, "A1"), "XML syntax error on line 1: invalid UTF-8")
|
|
|
|
|
|
|
|
f.CalcChain = nil
|
|
|
|
f.Pkg.Store(defaultXMLPathCalcChain, MacintoshCyrillicCharset)
|
|
|
|
assert.EqualError(t, f.SetCellFormula("Sheet1", "A1", ""), "XML syntax error on line 1: invalid UTF-8")
|
|
|
|
|
|
|
|
formulaType, ref := STCellFormulaTypeShared, "C1:C5"
|
|
|
|
assert.NoError(t, f.SetCellFormula("Sheet1", "C1", "=A1+B1", FormulaOpts{Ref: &ref, Type: &formulaType}))
|
2022-11-13 00:40:04 +08:00
|
|
|
|
|
|
|
// Test delete calculation chain with unsupported charset calculation chain.
|
2022-11-12 00:02:11 +08:00
|
|
|
f.CalcChain = nil
|
|
|
|
f.Pkg.Store(defaultXMLPathCalcChain, MacintoshCyrillicCharset)
|
|
|
|
assert.EqualError(t, f.SetCellValue("Sheet1", "C1", true), "XML syntax error on line 1: invalid UTF-8")
|
2022-11-13 00:40:04 +08:00
|
|
|
|
|
|
|
// Test delete calculation chain with unsupported charset content types.
|
|
|
|
f.ContentTypes = nil
|
|
|
|
f.Pkg.Store(defaultXMLPathContentTypes, MacintoshCyrillicCharset)
|
|
|
|
assert.EqualError(t, f.deleteCalcChain(1, "A1"), "XML syntax error on line 1: invalid UTF-8")
|
2019-12-22 00:02:09 +08:00
|
|
|
}
|