From ae2865d9237cfd27d7bc4fbef3870b3361597be8 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 22 Dec 2019 00:02:09 +0800 Subject: Improve code coverage unit tests --- docProps_test.go | 13 +++++++++++++ 1 file changed, 13 insertions(+) (limited to 'docProps_test.go') diff --git a/docProps_test.go b/docProps_test.go index df3122b..30c3149 100644 --- a/docProps_test.go +++ b/docProps_test.go @@ -16,6 +16,8 @@ import ( "github.com/stretchr/testify/assert" ) +var MacintoshCyrillicCharset = []byte{0x8F, 0xF0, 0xE8, 0xE2, 0xE5, 0xF2, 0x20, 0xEC, 0xE8, 0xF0} + func TestSetDocProps(t *testing.T) { f, err := OpenFile(filepath.Join("test", "Book1.xlsx")) if !assert.NoError(t, err) { @@ -40,6 +42,11 @@ func TestSetDocProps(t *testing.T) { assert.NoError(t, f.SaveAs(filepath.Join("test", "TestSetDocProps.xlsx"))) f.XLSX["docProps/core.xml"] = nil assert.NoError(t, f.SetDocProps(&DocProperties{})) + + // Test unsupport charset + f = NewFile() + f.XLSX["docProps/core.xml"] = MacintoshCyrillicCharset + assert.EqualError(t, f.SetDocProps(&DocProperties{}), "xml decode error: XML syntax error on line 1: invalid UTF-8") } func TestGetDocProps(t *testing.T) { @@ -53,4 +60,10 @@ func TestGetDocProps(t *testing.T) { f.XLSX["docProps/core.xml"] = nil _, err = f.GetDocProps() assert.NoError(t, err) + + // Test unsupport charset + f = NewFile() + f.XLSX["docProps/core.xml"] = MacintoshCyrillicCharset + _, err = f.GetDocProps() + assert.EqualError(t, err, "xml decode error: XML syntax error on line 1: invalid UTF-8") } -- cgit v1.2.1