-
Notifications
You must be signed in to change notification settings - Fork 107
Expand file tree
/
Copy pathdraw2d_types_test.go
More file actions
163 lines (141 loc) · 3.72 KB
/
draw2d_types_test.go
File metadata and controls
163 lines (141 loc) · 3.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
// Copyright 2010 The draw2d Authors. All rights reserved.
// created: 07/02/2026 by draw2d contributors
package draw2d
import (
"image/color"
"testing"
)
func TestLineCap_String(t *testing.T) {
tests := []struct {
name string
cap LineCap
expected string
}{
{"RoundCap", RoundCap, "round"},
{"ButtCap", ButtCap, "cap"},
{"SquareCap", SquareCap, "square"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.cap.String(); got != tt.expected {
t.Errorf("LineCap.String() = %v, want %v", got, tt.expected)
}
})
}
}
func TestLineJoin_String(t *testing.T) {
tests := []struct {
name string
join LineJoin
expected string
}{
{"BevelJoin", BevelJoin, "bevel"},
{"RoundJoin", RoundJoin, "round"},
{"MiterJoin", MiterJoin, "miter"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := tt.join.String(); got != tt.expected {
t.Errorf("LineJoin.String() = %v, want %v", got, tt.expected)
}
})
}
}
func TestFillRule_Constants(t *testing.T) {
tests := []struct {
name string
rule FillRule
expected int
}{
{"FillRuleEvenOdd", FillRuleEvenOdd, 0},
{"FillRuleWinding", FillRuleWinding, 1},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if int(tt.rule) != tt.expected {
t.Errorf("%s = %v, want %v", tt.name, int(tt.rule), tt.expected)
}
})
}
}
func TestValign_Constants(t *testing.T) {
tests := []struct {
name string
valign Valign
expected int
}{
{"ValignTop", ValignTop, 0},
{"ValignCenter", ValignCenter, 1},
{"ValignBottom", ValignBottom, 2},
{"ValignBaseline", ValignBaseline, 3},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if int(tt.valign) != tt.expected {
t.Errorf("%s = %v, want %v", tt.name, int(tt.valign), tt.expected)
}
})
}
}
func TestHalign_Constants(t *testing.T) {
tests := []struct {
name string
halign Halign
expected int
}{
{"HalignLeft", HalignLeft, 0},
{"HalignCenter", HalignCenter, 1},
{"HalignRight", HalignRight, 2},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if int(tt.halign) != tt.expected {
t.Errorf("%s = %v, want %v", tt.name, int(tt.halign), tt.expected)
}
})
}
}
func TestStrokeStyle_Defaults(t *testing.T) {
// Create a StrokeStyle and verify fields can be set and read
style := StrokeStyle{
Color: color.RGBA{255, 0, 0, 255},
Width: 5.0,
LineCap: RoundCap,
LineJoin: MiterJoin,
DashOffset: 2.5,
Dash: []float64{10, 5},
}
if style.Width != 5.0 {
t.Errorf("StrokeStyle.Width = %v, want %v", style.Width, 5.0)
}
if style.LineCap != RoundCap {
t.Errorf("StrokeStyle.LineCap = %v, want %v", style.LineCap, RoundCap)
}
if style.LineJoin != MiterJoin {
t.Errorf("StrokeStyle.LineJoin = %v, want %v", style.LineJoin, MiterJoin)
}
if style.DashOffset != 2.5 {
t.Errorf("StrokeStyle.DashOffset = %v, want %v", style.DashOffset, 2.5)
}
if len(style.Dash) != 2 || style.Dash[0] != 10 || style.Dash[1] != 5 {
t.Errorf("StrokeStyle.Dash = %v, want %v", style.Dash, []float64{10, 5})
}
r, g, b, a := style.Color.RGBA()
if r != 65535 || g != 0 || b != 0 || a != 65535 {
t.Errorf("StrokeStyle.Color RGBA values incorrect")
}
}
func TestSolidFillStyle_Defaults(t *testing.T) {
// Create a SolidFillStyle and verify fields can be set and read
style := SolidFillStyle{
Color: color.RGBA{0, 255, 0, 255},
FillRule: FillRuleWinding,
}
if style.FillRule != FillRuleWinding {
t.Errorf("SolidFillStyle.FillRule = %v, want %v", style.FillRule, FillRuleWinding)
}
r, g, b, a := style.Color.RGBA()
if r != 0 || g != 65535 || b != 0 || a != 65535 {
t.Errorf("SolidFillStyle.Color RGBA values incorrect")
}
}