Debian Codegraph @

style_test.go

raw symbols SCIP
1 package chart
2
3 import (
4 "testing"
5
6 "github.com/golang/freetype/truetype"
7 "github.com/wcharczuk/go-chart/v2/drawing"
8 "github.com/wcharczuk/go-chart/v2/testutil"
9 )
10
11 func TestStyleIsZero(t *testing.T) {
12 // replaced new assertions helper
13 zero := Style{}
14 testutil.AssertTrue(t, zero.IsZero())
15
16 strokeColor := Style{StrokeColor: drawing.ColorWhite}
17 testutil.AssertFalse(t, strokeColor.IsZero())
18
19 fillColor := Style{FillColor: drawing.ColorWhite}
20 testutil.AssertFalse(t, fillColor.IsZero())
21
22 strokeWidth := Style{StrokeWidth: 5.0}
23 testutil.AssertFalse(t, strokeWidth.IsZero())
24
25 fontSize := Style{FontSize: 12.0}
26 testutil.AssertFalse(t, fontSize.IsZero())
27
28 fontColor := Style{FontColor: drawing.ColorWhite}
29 testutil.AssertFalse(t, fontColor.IsZero())
30
31 font := Style{Font: &truetype.Font{}}
32 testutil.AssertFalse(t, font.IsZero())
33 }
34
35 func TestStyleGetStrokeColor(t *testing.T) {
36 // replaced new assertions helper
37
38 unset := Style{}
39 testutil.AssertEqual(t, drawing.ColorTransparent, unset.GetStrokeColor())
40 testutil.AssertEqual(t, drawing.ColorWhite, unset.GetStrokeColor(drawing.ColorWhite))
41
42 set := Style{StrokeColor: drawing.ColorWhite}
43 testutil.AssertEqual(t, drawing.ColorWhite, set.GetStrokeColor())
44 testutil.AssertEqual(t, drawing.ColorWhite, set.GetStrokeColor(drawing.ColorBlack))
45 }
46
47 func TestStyleGetFillColor(t *testing.T) {
48 // replaced new assertions helper
49
50 unset := Style{}
51 testutil.AssertEqual(t, drawing.ColorTransparent, unset.GetFillColor())
52 testutil.AssertEqual(t, drawing.ColorWhite, unset.GetFillColor(drawing.ColorWhite))
53
54 set := Style{FillColor: drawing.ColorWhite}
55 testutil.AssertEqual(t, drawing.ColorWhite, set.GetFillColor())
56 testutil.AssertEqual(t, drawing.ColorWhite, set.GetFillColor(drawing.ColorBlack))
57 }
58
59 func TestStyleGetStrokeWidth(t *testing.T) {
60 // replaced new assertions helper
61
62 unset := Style{}
63 testutil.AssertEqual(t, DefaultStrokeWidth, unset.GetStrokeWidth())
64 testutil.AssertEqual(t, DefaultStrokeWidth+1, unset.GetStrokeWidth(DefaultStrokeWidth+1))
65
66 set := Style{StrokeWidth: DefaultStrokeWidth + 2}
67 testutil.AssertEqual(t, DefaultStrokeWidth+2, set.GetStrokeWidth())
68 testutil.AssertEqual(t, DefaultStrokeWidth+2, set.GetStrokeWidth(DefaultStrokeWidth+1))
69 }
70
71 func TestStyleGetFontSize(t *testing.T) {
72 // replaced new assertions helper
73
74 unset := Style{}
75 testutil.AssertEqual(t, DefaultFontSize, unset.GetFontSize())
76 testutil.AssertEqual(t, DefaultFontSize+1, unset.GetFontSize(DefaultFontSize+1))
77
78 set := Style{FontSize: DefaultFontSize + 2}
79 testutil.AssertEqual(t, DefaultFontSize+2, set.GetFontSize())
80 testutil.AssertEqual(t, DefaultFontSize+2, set.GetFontSize(DefaultFontSize+1))
81 }
82
83 func TestStyleGetFontColor(t *testing.T) {
84 // replaced new assertions helper
85
86 unset := Style{}
87 testutil.AssertEqual(t, drawing.ColorTransparent, unset.GetFontColor())
88 testutil.AssertEqual(t, drawing.ColorWhite, unset.GetFontColor(drawing.ColorWhite))
89
90 set := Style{FontColor: drawing.ColorWhite}
91 testutil.AssertEqual(t, drawing.ColorWhite, set.GetFontColor())
92 testutil.AssertEqual(t, drawing.ColorWhite, set.GetFontColor(drawing.ColorBlack))
93 }
94
95 func TestStyleGetFont(t *testing.T) {
96 // replaced new assertions helper
97
98 f, err := GetDefaultFont()
99 testutil.AssertNil(t, err)
100
101 unset := Style{}
102 testutil.AssertNil(t, unset.GetFont())
103 testutil.AssertEqual(t, f, unset.GetFont(f))
104
105 set := Style{Font: f}
106 testutil.AssertNotNil(t, set.GetFont())
107 }
108
109 func TestStyleGetPadding(t *testing.T) {
110 // replaced new assertions helper
111
112 unset := Style{}
113 testutil.AssertTrue(t, unset.GetPadding().IsZero())
114 testutil.AssertFalse(t, unset.GetPadding(DefaultBackgroundPadding).IsZero())
115 testutil.AssertEqual(t, DefaultBackgroundPadding, unset.GetPadding(DefaultBackgroundPadding))
116
117 set := Style{Padding: DefaultBackgroundPadding}
118 testutil.AssertFalse(t, set.GetPadding().IsZero())
119 testutil.AssertEqual(t, DefaultBackgroundPadding, set.GetPadding())
120 testutil.AssertEqual(t, DefaultBackgroundPadding, set.GetPadding(Box{
121 Top: DefaultBackgroundPadding.Top + 1,
122 Left: DefaultBackgroundPadding.Left + 1,
123 Right: DefaultBackgroundPadding.Right + 1,
124 Bottom: DefaultBackgroundPadding.Bottom + 1,
125 }))
126 }
127
128 func TestStyleWithDefaultsFrom(t *testing.T) {
129 // replaced new assertions helper
130
131 f, err := GetDefaultFont()
132 testutil.AssertNil(t, err)
133
134 unset := Style{}
135 set := Style{
136 StrokeColor: drawing.ColorWhite,
137 StrokeWidth: 5.0,
138 FillColor: drawing.ColorWhite,
139 FontColor: drawing.ColorWhite,
140 Font: f,
141 Padding: DefaultBackgroundPadding,
142 }
143
144 coalesced := unset.InheritFrom(set)
145 testutil.AssertEqual(t, set, coalesced)
146 }
147
148 func TestStyleGetStrokeOptions(t *testing.T) {
149 // replaced new assertions helper
150
151 set := Style{
152 StrokeColor: drawing.ColorWhite,
153 StrokeWidth: 5.0,
154 FillColor: drawing.ColorWhite,
155 FontColor: drawing.ColorWhite,
156 Padding: DefaultBackgroundPadding,
157 }
158 svgStroke := set.GetStrokeOptions()
159 testutil.AssertFalse(t, svgStroke.StrokeColor.IsZero())
160 testutil.AssertNotZero(t, svgStroke.StrokeWidth)
161 testutil.AssertTrue(t, svgStroke.FillColor.IsZero())
162 testutil.AssertTrue(t, svgStroke.FontColor.IsZero())
163 }
164
165 func TestStyleGetFillOptions(t *testing.T) {
166 // replaced new assertions helper
167
168 set := Style{
169 StrokeColor: drawing.ColorWhite,
170 StrokeWidth: 5.0,
171 FillColor: drawing.ColorWhite,
172 FontColor: drawing.ColorWhite,
173 Padding: DefaultBackgroundPadding,
174 }
175 svgFill := set.GetFillOptions()
176 testutil.AssertFalse(t, svgFill.FillColor.IsZero())
177 testutil.AssertZero(t, svgFill.StrokeWidth)
178 testutil.AssertTrue(t, svgFill.StrokeColor.IsZero())
179 testutil.AssertTrue(t, svgFill.FontColor.IsZero())
180 }
181
182 func TestStyleGetFillAndStrokeOptions(t *testing.T) {
183 // replaced new assertions helper
184
185 set := Style{
186 StrokeColor: drawing.ColorWhite,
187 StrokeWidth: 5.0,
188 FillColor: drawing.ColorWhite,
189 FontColor: drawing.ColorWhite,
190 Padding: DefaultBackgroundPadding,
191 }
192 svgFillAndStroke := set.GetFillAndStrokeOptions()
193 testutil.AssertFalse(t, svgFillAndStroke.FillColor.IsZero())
194 testutil.AssertNotZero(t, svgFillAndStroke.StrokeWidth)
195 testutil.AssertFalse(t, svgFillAndStroke.StrokeColor.IsZero())
196 testutil.AssertTrue(t, svgFillAndStroke.FontColor.IsZero())
197 }
198
199 func TestStyleGetTextOptions(t *testing.T) {
200 // replaced new assertions helper
201
202 set := Style{
203 StrokeColor: drawing.ColorWhite,
204 StrokeWidth: 5.0,
205 FillColor: drawing.ColorWhite,
206 FontColor: drawing.ColorWhite,
207 Padding: DefaultBackgroundPadding,
208 }
209 svgStroke := set.GetTextOptions()
210 testutil.AssertTrue(t, svgStroke.StrokeColor.IsZero())
211 testutil.AssertZero(t, svgStroke.StrokeWidth)
212 testutil.AssertTrue(t, svgStroke.FillColor.IsZero())
213 testutil.AssertFalse(t, svgStroke.FontColor.IsZero())
214 }