-
Notifications
You must be signed in to change notification settings - Fork 1
/
ivg_test.go
70 lines (62 loc) · 1.41 KB
/
ivg_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
package ivg_test
import (
"bytes"
"testing"
"github.com/reactivego/ivg"
"github.com/reactivego/ivg/decode"
"github.com/reactivego/ivg/encode"
"github.com/reactivego/ivg/generate"
"github.com/reactivego/ivg/render"
)
func TestEncodeDecode(t *testing.T) {
var e = &encode.Encoder{}
e.HighResolutionCoordinates = true
e.Reset(
ivg.ViewBox{
MinX: -24, MinY: -24,
MaxX: +24, MaxY: +24,
},
ivg.DefaultPalette,
)
e.StartPath(0, 0, -20)
e.AbsCubeTo(-11.05, -20, -20, -11.05, -20, 0)
e.RelSmoothCubeTo(8.95, 20, 20, 20)
e.RelSmoothCubeTo(20, -8.95, 20, -20)
e.AbsSmoothCubeTo(11.05, -20, 0, -20)
e.ClosePathRelMoveTo(2, 30)
e.RelHLineTo(-4)
e.AbsVLineTo(-2)
e.RelHLineTo(4)
e.RelVLineTo(12)
e.ClosePathRelMoveTo(0, -16)
e.RelHLineTo(-4)
e.RelVLineTo(-4)
e.RelHLineTo(4)
e.RelVLineTo(4)
e.ClosePathEndPath()
expect, err := e.Bytes()
if err != nil {
t.Fatalf("encoding: %v", err)
}
e = &encode.Encoder{}
e.HighResolutionCoordinates = true
if err := decode.Decode(e, expect); err != nil {
t.Fatalf("decoding: %v", err)
}
actual, err := e.Bytes()
if err != nil {
t.Fatalf("encoding: %v", err)
} else {
if len(expect) != len(actual) {
t.Fatalf("len(actual)!=len(expect): %d %d", len(actual), len(expect))
} else {
if !bytes.Equal(expect, actual) {
t.Fatal("actual!=expect")
}
}
}
var r = &render.Renderer{}
var g generate.Generator
g.SetDestination(e)
g.SetDestination(r)
}