-
Notifications
You must be signed in to change notification settings - Fork 22
/
template_test.go
88 lines (79 loc) · 2.08 KB
/
template_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
86
87
88
//
// Copyright (c) 2022-2023 Markku Rossi
//
// All rights reserved.
//
package circuit
import (
"testing"
)
var tmplXOR = `<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
<path fill="none" stroke="#000" stroke-width="1"
d="M {{25}} {{20}}
c {{10}} {{10}} {{40}} {{10}} {{50}} 0" />
<path fill="none" stroke="#000" stroke-width="1"
d="M 25 25
c 10 10 40 10 50 0" />
<path fill="none" stroke="#000" stroke-width="1"
d="M 75 25
v 25
s 0 10 -25 25 " />
<path fill="none" stroke="#000" stroke-width="1"
d="M 25 25
v 25
s 0 10 25 25 " />
<!-- Wires -->
<path fill="none" stroke="#000" stroke-width="1"
d="M 35 0
v 25
z" />
<path fill="none" stroke="#000" stroke-width="1"
d="M 65 0
v 25
z" />
<path fill="none" stroke="#000" stroke-width="1"
d="M 50 75
v 25
z" />
</svg>
`
var tmplXORExpanded = `<svg xmlns="http://www.w3.org/2000/svg" width="100" height="100">
<path fill="none" stroke="#000" stroke-width="1"
d="M 6.25 5
c 2.5 2.5 10 2.5 12.5 0" />
<path fill="none" stroke="#000" stroke-width="1"
d="M 25 25
c 10 10 40 10 50 0" />
<path fill="none" stroke="#000" stroke-width="1"
d="M 75 25
v 25
s 0 10 -25 25 " />
<path fill="none" stroke="#000" stroke-width="1"
d="M 25 25
v 25
s 0 10 25 25 " />
<!-- Wires -->
<path fill="none" stroke="#000" stroke-width="1"
d="M 35 0
v 25
z" />
<path fill="none" stroke="#000" stroke-width="1"
d="M 65 0
v 25
z" />
<path fill="none" stroke="#000" stroke-width="1"
d="M 50 75
v 25
z" />
</svg>
`
func TestTemplate(t *testing.T) {
tmpl := NewTemplate(tmplXOR)
tmpl.IntCvt = func(v int) float64 {
return float64(v) * 25 / 100
}
expanded := tmpl.Expand()
if expanded != tmplXORExpanded {
t.Errorf("template expansion failed: got\n%v\n", expanded)
}
}