-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpath_builder_test.go
More file actions
164 lines (136 loc) · 3.89 KB
/
Copy pathpath_builder_test.go
File metadata and controls
164 lines (136 loc) · 3.89 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
164
package gg
import (
"testing"
)
func TestPathBuilder_Basic(t *testing.T) {
path := BuildPath().
MoveTo(0, 0).
LineTo(100, 0).
LineTo(100, 100).
Close().
Build()
if path == nil {
t.Fatal("expected non-nil path")
}
// Check path has elements
count := path.NumVerbs()
if count != 4 { // MoveTo, LineTo, LineTo, Close
t.Errorf("expected 4 elements, got %d", count)
}
}
func TestPathBuilder_Shapes(t *testing.T) {
tests := []struct {
name string
builder func() *PathBuilder
minElems int
}{
{"Rect", func() *PathBuilder { return BuildPath().Rect(0, 0, 100, 100) }, 5},
{"Circle", func() *PathBuilder { return BuildPath().Circle(50, 50, 25) }, 5},
{"Ellipse", func() *PathBuilder { return BuildPath().Ellipse(50, 50, 30, 20) }, 5},
{"Polygon5", func() *PathBuilder { return BuildPath().Polygon(50, 50, 25, 5) }, 6},
{"Star5", func() *PathBuilder { return BuildPath().Star(50, 50, 30, 15, 5) }, 11},
{"RoundRect", func() *PathBuilder { return BuildPath().RoundRect(0, 0, 100, 100, 10) }, 9},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
path := tt.builder().Build()
count := path.NumVerbs()
if count < tt.minElems {
t.Errorf("expected at least %d elements, got %d", tt.minElems, count)
}
})
}
}
func TestPathBuilder_Chaining(t *testing.T) {
// Test that chaining works correctly
path := BuildPath().
Circle(100, 100, 50).
Rect(200, 50, 100, 100).
Star(400, 100, 40, 20, 5).
Build()
if path == nil {
t.Fatal("expected non-nil path")
}
// Should have elements from all three shapes
count := path.NumVerbs()
// Circle: 6 (MoveTo + 4 CubicTo + Close)
// Rect: 5 (MoveTo + 3 LineTo + Close)
// Star: 11 (MoveTo + 9 LineTo + Close)
// Total: 22
if count < 20 {
t.Errorf("expected at least 20 elements from chained shapes, got %d", count)
}
}
func TestPathBuilder_InvalidPolygon(t *testing.T) {
// Polygon with < 3 sides should do nothing
path := BuildPath().Polygon(50, 50, 25, 2).Build()
count := path.NumVerbs()
if count != 0 {
t.Errorf("expected 0 elements for invalid polygon, got %d", count)
}
}
func TestPathBuilder_InvalidStar(t *testing.T) {
// Star with < 3 points should do nothing
path := BuildPath().Star(50, 50, 30, 15, 2).Build()
count := path.NumVerbs()
if count != 0 {
t.Errorf("expected 0 elements for invalid star, got %d", count)
}
}
func TestPathBuilder_QuadTo(t *testing.T) {
path := BuildPath().
MoveTo(0, 0).
QuadTo(50, 100, 100, 0).
Build()
if path == nil {
t.Fatal("expected non-nil path")
}
count := path.NumVerbs()
if count != 2 { // MoveTo, QuadTo
t.Errorf("expected 2 elements, got %d", count)
}
}
func TestPathBuilder_CubicTo(t *testing.T) {
path := BuildPath().
MoveTo(0, 0).
CubicTo(25, 100, 75, 100, 100, 0).
Build()
if path == nil {
t.Fatal("expected non-nil path")
}
count := path.NumVerbs()
if count != 2 { // MoveTo, CubicTo
t.Errorf("expected 2 elements, got %d", count)
}
}
func TestPathBuilder_PathAlias(t *testing.T) {
builder := BuildPath().MoveTo(0, 0).LineTo(100, 100)
// Both Build() and Path() should return the same path
pathFromBuild := builder.Build()
pathFromPath := builder.Path()
if pathFromBuild != pathFromPath {
t.Error("Build() and Path() should return the same path")
}
}
func TestPathBuilder_RoundRectRadiusClamping(t *testing.T) {
// Radius larger than half the smaller dimension should be clamped
path := BuildPath().RoundRect(0, 0, 100, 50, 100).Build()
if path == nil {
t.Fatal("expected non-nil path")
}
// Should still produce a valid path (essentially a pill shape)
count := path.NumVerbs()
if count < 9 {
t.Errorf("expected at least 9 elements for rounded rect, got %d", count)
}
}
func TestPathBuilder_EmptyPath(t *testing.T) {
path := BuildPath().Build()
if path == nil {
t.Fatal("expected non-nil path")
}
count := path.NumVerbs()
if count != 0 {
t.Errorf("expected 0 elements for empty path, got %d", count)
}
}