-
Notifications
You must be signed in to change notification settings - Fork 3
/
svg_test.go
85 lines (74 loc) · 2.36 KB
/
svg_test.go
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
package bg
import (
"testing"
)
func TestSvgParseAbsolutePath(t *testing.T) {
//absolute path - triangle
path := svgPath{D: "M 100 100 L 300 100 L 200 300 z"}
path.generatePath()
if len(path.Polygons) != 1 {
t.Errorf("Did not generate 1 polygon: %+v\n", path)
}
expectedPoints := []svgVert{{100, 100}, {300, 100}, {200, 300}}
for idx, pt := range expectedPoints {
if path.Polygons[0].Points[idx] != pt {
t.Errorf("Point[%d] %v != %v", idx, path.Polygons[0].Points[idx], pt)
}
}
}
func testSvgParseAbsoluteRepeatCommands(t *testing.T) {
//absolute path repeat commands - triangle
path := svgPath{D: "M 100 100 L 300 100 200 300 z"}
path.generatePath()
if len(path.Polygons) != 1 {
t.Errorf("Did not generate 1 polygon: %+v\n", path)
}
expectedPoints := []svgVert{{100, 100}, {300, 100}, {200, 300}}
for idx, pt := range expectedPoints {
if path.Polygons[0].Points[idx] != pt {
t.Errorf("Point[%d] %v != %v", idx, path.Polygons[0].Points[idx], pt)
}
}
}
func TestSvgParseRelative(t *testing.T) {
//relative path - triangle
path := svgPath{D: "M 100 100 l 200 0 l -100 200 z"}
path.generatePath()
if len(path.Polygons) != 1 {
t.Errorf("Did not generate 1 polygon: %+v\n", path)
}
expectedPoints := []svgVert{{100, 100}, {300, 100}, {200, 300}}
for idx, pt := range expectedPoints {
if path.Polygons[0].Points[idx] != pt {
t.Errorf("Point[%d] %v != %v", idx, path.Polygons[0].Points[idx], pt)
}
}
}
func TestSvgParseCommas(t *testing.T) {
//relative path comma seperators- triangle
path := svgPath{D: "M 100,101 l 200,0 l -100,200 z"}
path.generatePath()
if len(path.Polygons) != 1 {
t.Errorf("Did not generate 1 polygon: %+v\n", path)
}
expectedPoints := []svgVert{{100, 101}, {300, 101}, {200, 301}}
for idx, pt := range expectedPoints {
if path.Polygons[0].Points[idx] != pt {
t.Errorf("Point[%d] %v != %v", idx, path.Polygons[0].Points[idx], pt)
}
}
}
func TestSvgParseFloats(t *testing.T) {
//relative path comma seperators- triangle
path := svgPath{D: "M 100.4,101.7 l 200.2,0 l -100.5,200.7 z"}
path.generatePath()
if len(path.Polygons) != 1 {
t.Errorf("Did not generate 1 polygon: %+v\n", path)
}
expectedPoints := []svgVert{{100, 101}, {300, 101}, {200, 301}}
for idx, pt := range expectedPoints {
if path.Polygons[0].Points[idx] != pt {
t.Errorf("Point[%d] %v != %v", idx, path.Polygons[0].Points[idx], pt)
}
}
}