@@ -12,18 +12,19 @@ func TestAddShape(t *testing.T) {
12
12
if ! assert .NoError (t , err ) {
13
13
t .FailNow ()
14
14
}
15
- shape := & Shape {
15
+ assert .NoError (t , f .AddShape ("Sheet1" , & Shape {
16
+ Cell : "A30" ,
16
17
Type : "rect" ,
17
18
Paragraph : []RichTextRun {
18
19
{Text : "Rectangle" , Font : & Font {Color : "CD5C5C" }},
19
20
{Text : "Shape" , Font : & Font {Bold : true , Color : "2980B9" }},
20
21
},
21
- }
22
- assert .NoError (t , f .AddShape ("Sheet1" , "A30" , shape ))
23
- assert .NoError (t , f .AddShape ("Sheet1" , "B30" , & Shape {Type : "rect" , Paragraph : []RichTextRun {{Text : "Rectangle" }, {}}}))
24
- assert .NoError (t , f .AddShape ("Sheet1" , "C30" , & Shape {Type : "rect" }))
25
- assert .EqualError (t , f .AddShape ("Sheet3" , "H1" ,
22
+ }))
23
+ assert .NoError (t , f .AddShape ("Sheet1" , & Shape {Cell : "B30" , Type : "rect" , Paragraph : []RichTextRun {{Text : "Rectangle" }, {}}}))
24
+ assert .NoError (t , f .AddShape ("Sheet1" , & Shape {Cell : "C30" , Type : "rect" }))
25
+ assert .EqualError (t , f .AddShape ("Sheet3" ,
26
26
& Shape {
27
+ Cell : "H1" ,
27
28
Type : "ellipseRibbon" ,
28
29
Line : ShapeLine {Color : "4286F4" },
29
30
Fill : Fill {Color : []string {"8EB9FF" }},
@@ -41,15 +42,24 @@ func TestAddShape(t *testing.T) {
41
42
},
42
43
},
43
44
), "sheet Sheet3 does not exist" )
44
- assert .EqualError (t , f .AddShape ("Sheet3" , "H1" , nil ), ErrParameterInvalid .Error ())
45
- assert .EqualError (t , f .AddShape ("Sheet1" , "A" , shape ), newCellNameToCoordinatesError ("A" , newInvalidCellNameError ("A" )).Error ())
45
+ assert .EqualError (t , f .AddShape ("Sheet3" , nil ), ErrParameterInvalid .Error ())
46
+ assert .EqualError (t , f .AddShape ("Sheet1" , & Shape {Cell : "A1" }), ErrParameterInvalid .Error ())
47
+ assert .EqualError (t , f .AddShape ("Sheet1" , & Shape {
48
+ Cell : "A" ,
49
+ Type : "rect" ,
50
+ Paragraph : []RichTextRun {
51
+ {Text : "Rectangle" , Font : & Font {Color : "CD5C5C" }},
52
+ {Text : "Shape" , Font : & Font {Bold : true , Color : "2980B9" }},
53
+ },
54
+ }), newCellNameToCoordinatesError ("A" , newInvalidCellNameError ("A" )).Error ())
46
55
assert .NoError (t , f .SaveAs (filepath .Join ("test" , "TestAddShape1.xlsx" )))
47
56
48
57
// Test add first shape for given sheet
49
58
f = NewFile ()
50
59
lineWidth := 1.2
51
- assert .NoError (t , f .AddShape ("Sheet1" , "A1" ,
60
+ assert .NoError (t , f .AddShape ("Sheet1" ,
52
61
& Shape {
62
+ Cell : "A1" ,
53
63
Type : "ellipseRibbon" ,
54
64
Line : ShapeLine {Color : "4286F4" , Width : & lineWidth },
55
65
Fill : Fill {Color : []string {"8EB9FF" }},
@@ -69,16 +79,23 @@ func TestAddShape(t *testing.T) {
69
79
}))
70
80
assert .NoError (t , f .SaveAs (filepath .Join ("test" , "TestAddShape2.xlsx" )))
71
81
// Test add shape with invalid sheet name
72
- assert .EqualError (t , f .AddShape ("Sheet:1" , "A30" , shape ), ErrSheetNameInvalid .Error ())
82
+ assert .EqualError (t , f .AddShape ("Sheet:1" , & Shape {
83
+ Cell : "A30" ,
84
+ Type : "rect" ,
85
+ Paragraph : []RichTextRun {
86
+ {Text : "Rectangle" , Font : & Font {Color : "CD5C5C" }},
87
+ {Text : "Shape" , Font : & Font {Bold : true , Color : "2980B9" }},
88
+ },
89
+ }), ErrSheetNameInvalid .Error ())
73
90
// Test add shape with unsupported charset style sheet
74
91
f .Styles = nil
75
92
f .Pkg .Store (defaultXMLPathStyles , MacintoshCyrillicCharset )
76
- assert .EqualError (t , f .AddShape ("Sheet1" , "B30" , & Shape { Type : "rect" , Paragraph : []RichTextRun {{Text : "Rectangle" }, {}}}), "XML syntax error on line 1: invalid UTF-8" )
93
+ assert .EqualError (t , f .AddShape ("Sheet1" , & Shape { Cell : "B30" , Type : "rect" , Paragraph : []RichTextRun {{Text : "Rectangle" }, {}}}), "XML syntax error on line 1: invalid UTF-8" )
77
94
// Test add shape with unsupported charset content types
78
95
f = NewFile ()
79
96
f .ContentTypes = nil
80
97
f .Pkg .Store (defaultXMLPathContentTypes , MacintoshCyrillicCharset )
81
- assert .EqualError (t , f .AddShape ("Sheet1" , "B30" , & Shape { Type : "rect" , Paragraph : []RichTextRun {{Text : "Rectangle" }, {}}}), "XML syntax error on line 1: invalid UTF-8" )
98
+ assert .EqualError (t , f .AddShape ("Sheet1" , & Shape { Cell : "B30" , Type : "rect" , Paragraph : []RichTextRun {{Text : "Rectangle" }, {}}}), "XML syntax error on line 1: invalid UTF-8" )
82
99
}
83
100
84
101
func TestAddDrawingShape (t * testing.T ) {
0 commit comments