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 --- comment_test.go | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 comment_test.go (limited to 'comment_test.go') diff --git a/comment_test.go b/comment_test.go new file mode 100644 index 0000000..dd07951 --- /dev/null +++ b/comment_test.go @@ -0,0 +1,56 @@ +// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// this source code is governed by a BSD-style license that can be found in +// the LICENSE file. +// +// Package excelize providing a set of functions that allow you to write to +// and read from XLSX files. Support reads and writes XLSX file generated by +// Microsoft Excelâ„¢ 2007 and later. Support save file without losing original +// charts of XLSX. This library needs Go version 1.10 or later. + +package excelize + +import ( + "path/filepath" + "strings" + "testing" + + "github.com/stretchr/testify/assert" +) + +func TestAddComments(t *testing.T) { + f, err := prepareTestBook1() + if !assert.NoError(t, err) { + t.FailNow() + } + + s := strings.Repeat("c", 32768) + assert.NoError(t, f.AddComment("Sheet1", "A30", `{"author":"`+s+`","text":"`+s+`"}`)) + assert.NoError(t, f.AddComment("Sheet2", "B7", `{"author":"Excelize: ","text":"This is a comment."}`)) + + // Test add comment on not exists worksheet. + assert.EqualError(t, f.AddComment("SheetN", "B7", `{"author":"Excelize: ","text":"This is a comment."}`), "sheet SheetN is not exist") + + if assert.NoError(t, f.SaveAs(filepath.Join("test", "TestAddComments.xlsx"))) { + assert.Len(t, f.GetComments(), 2) + } +} + +func TestDecodeVMLDrawingReader(t *testing.T) { + f := NewFile() + path := "xl/drawings/vmlDrawing1.xml" + f.XLSX[path] = MacintoshCyrillicCharset + f.decodeVMLDrawingReader(path) +} + +func TestCommentsReader(t *testing.T) { + f := NewFile() + path := "xl/comments1.xml" + f.XLSX[path] = MacintoshCyrillicCharset + f.commentsReader(path) +} + +func TestCountComments(t *testing.T) { + f := NewFile() + f.Comments["xl/comments1.xml"] = nil + assert.Equal(t, f.countComments(), 1) +} -- cgit v1.2.1 From 09485b3f9f0aefc58d51462aed65c2416205c591 Mon Sep 17 00:00:00 2001 From: xuri Date: Sun, 29 Dec 2019 16:02:31 +0800 Subject: Improve code coverage unit tests --- comment_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'comment_test.go') diff --git a/comment_test.go b/comment_test.go index dd07951..5b83162 100644 --- a/comment_test.go +++ b/comment_test.go @@ -1,4 +1,4 @@ -// Copyright 2016 - 2019 The excelize Authors. All rights reserved. Use of +// Copyright 2016 - 2020 The excelize Authors. All rights reserved. Use of // this source code is governed by a BSD-style license that can be found in // the LICENSE file. // -- cgit v1.2.1 From 3ce4b91be96589847823b6c1b6c123ba7880310f Mon Sep 17 00:00:00 2001 From: xuri Date: Tue, 31 Mar 2020 00:02:00 +0800 Subject: Resolve #345, fix missing comments by GetComments --- comment_test.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'comment_test.go') diff --git a/comment_test.go b/comment_test.go index 5b83162..955d4e8 100644 --- a/comment_test.go +++ b/comment_test.go @@ -29,10 +29,17 @@ func TestAddComments(t *testing.T) { // Test add comment on not exists worksheet. assert.EqualError(t, f.AddComment("SheetN", "B7", `{"author":"Excelize: ","text":"This is a comment."}`), "sheet SheetN is not exist") - + // Test add comment on with illegal cell coordinates + assert.EqualError(t, f.AddComment("Sheet1", "A", `{"author":"Excelize: ","text":"This is a comment."}`), `cannot convert cell "A" to coordinates: invalid cell name "A"`) if assert.NoError(t, f.SaveAs(filepath.Join("test", "TestAddComments.xlsx"))) { assert.Len(t, f.GetComments(), 2) } + + f.Comments["xl/comments2.xml"] = nil + f.XLSX["xl/comments2.xml"] = []byte(`Excelize: Excelize: `) + comments := f.GetComments() + assert.EqualValues(t, 2, len(comments["Sheet1"])) + assert.EqualValues(t, 1, len(comments["Sheet2"])) } func TestDecodeVMLDrawingReader(t *testing.T) { -- cgit v1.2.1