-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcounter_template_test.go
107 lines (92 loc) · 3.12 KB
/
counter_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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package counters
import (
"image/color"
"sync"
"testing"
"github.com/stretchr/testify/assert"
)
func TestExpandPrototypeCounterTemplate(t *testing.T) {
proto := CounterPrototype{
Counter: Counter{
Texts: []Text{{String: "text"}},
},
TextPrototypes: []TextPrototype{
{StringList: []string{"text1", "text2"}},
},
ImagePrototypes: []ImagePrototype{
{PathList: []string{"../assets/binoculars.png", "../assets/stripe.png"}},
},
}
prototypeTemplate := &CounterTemplate{
Prototypes: map[string]CounterPrototype{
"proto": proto,
"proto2": proto,
}}
filenamesInUse := &sync.Map{}
ct, err := prototypeTemplate.ExpandPrototypeCounterTemplate(filenamesInUse)
if assert.NoError(t, err) {
assert.Equal(t, 4, len(ct.Counters))
assert.Equal(t, "text", ct.Counters[0].Texts[0].String)
assert.Equal(t, "text1", ct.Counters[0].Texts[1].String)
assert.Equal(t, "../assets/binoculars.png", ct.Counters[0].Images[0].Path)
assert.Equal(t, "text", ct.Counters[1].Texts[0].String)
assert.Equal(t, "text2", ct.Counters[1].Texts[1].String)
assert.Equal(t, "../assets/stripe.png", ct.Counters[1].Images[0].Path)
assert.Equal(t, "text", ct.Counters[2].Texts[0].String)
assert.Equal(t, "text1", ct.Counters[2].Texts[1].String)
assert.Equal(t, "../assets/binoculars.png", ct.Counters[2].Images[0].Path)
assert.Equal(t, "text", ct.Counters[3].Texts[0].String)
assert.Equal(t, "text2", ct.Counters[3].Texts[1].String)
assert.Equal(t, "../assets/stripe.png", ct.Counters[3].Images[0].Path)
}
}
func intP(i int) *int {
return &i
}
func floatP(f float64) *float64 {
return &f
}
func TestApplyCounterWaterfallSettings(t *testing.T) {
white := "white"
ct := &CounterTemplate{
Settings: Settings{
Width: 100,
Height: 200,
FontHeight: 10,
FontPath: "assets/freesans.ttf",
FontColorS: "black",
BackgroundColor: &white,
Margins: floatP(5),
StrokeWidth: floatP(1),
},
Counters: []Counter{
{
Settings: Settings{
Margins: floatP(10),
FontHeight: 20,
},
Texts: []Text{{String: "text"}},
},
},
}
err := ct.ApplyCounterWaterfallSettings()
if !assert.NoError(t, err) {
t.Fatal()
}
assert.Equal(t, 20.0, ct.Counters[0].Settings.FontHeight)
assert.Equal(t, ColorFromStringOrDefault("black", color.Black), ct.Settings.FontColor)
assert.Equal(t, ColorFromStringOrDefault("black", color.Black), ct.Counters[0].Settings.FontColor)
assert.Equal(t, "white", *ct.Counters[0].Settings.BackgroundColor)
assert.Equal(t, 20.0, ct.Counters[0].Settings.FontHeight)
assert.Equal(t, 100, ct.Counters[0].Settings.Width)
assert.Equal(t, 200, ct.Counters[0].Settings.Height)
assert.Equal(t, 10.0, *ct.Counters[0].Settings.Margins)
// Override with zero values
ct.Counters[0].Settings.StrokeWidth = floatP(0)
ct.Counters[0].Settings.Width = 50
ct.ApplyCounterWaterfallSettings()
assert.Equal(t, 0.0, *ct.Counters[0].Settings.StrokeWidth, "StrokeWidth should be 1 for CT "+
"settings but 0 for counter because it was overriden")
assert.Equal(t, 50, ct.Counters[0].Settings.Width, "Width should be 50 for counter because it "+
"was overriden")
}