-
Notifications
You must be signed in to change notification settings - Fork 9
/
attributes_test.go
73 lines (56 loc) · 1.63 KB
/
attributes_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
package vitotrol
import (
"testing"
td "github.com/maxatome/go-testdeep"
)
func TestAttrRef(tt *testing.T) {
t := td.NewT(tt)
ar := AttrRef{
Type: TypeString,
Access: ReadOnly,
Name: "Foo",
Doc: "Documentation...",
}
t.CmpDeeply(ar.String(), "Foo: Documentation... (String - read-only)")
}
func TestAttributesVars(tt *testing.T) {
t := td.NewT(tt)
for name, aID := range AttributesNames2IDs {
tRef, ok := AttributesRef[aID]
if t.True(ok, "AttributesRef[%d] exists", aID) {
t.CmpDeeply(name, tRef.Name,
"ID %d: same name in AttributesRef and AttributesNames2IDs", aID)
}
}
for aID, tRef := range AttributesRef {
aID2, ok := AttributesNames2IDs[tRef.Name]
if t.True(ok, "AttributesNames2IDs[%s] exists", tRef.Name) {
t.CmpDeeply(aID, aID2,
tRef.Name+": same ID in AttributesRef and AttributesNames2IDs")
}
}
t.CmpDeeply(len(Attributes), len(AttributesRef))
for _, aID := range Attributes {
_, ok := AttributesRef[aID]
t.True(ok, "ID %d of Attributes is present in AttributesRef")
}
// Add custom attribute
require := t.FailureIsFatal()
require.CmpDeeply(AttributesRef, td.Not(td.ContainsKey(9999)))
AddAttributeRef(9999, AttrRef{
Type: TypeDouble,
Access: ReadOnly,
Name: "FooBar",
})
require.CmpDeeply(AttributesRef, td.ContainsKey(AttrID(9999)))
t.CmpDeeply(AttributesNames2IDs["FooBar"], AttrID(9999))
t.CmpDeeply(Attributes, td.Contains(AttrID(9999)))
t.True(AttributesRef[AttrID(9999)].Custom)
}
func TestValue(tt *testing.T) {
t := td.NewT(tt)
v := Value{Value: "34"}
t.CmpDeeply(v.Num(), float64(34))
v = Value{Value: "foo"}
t.CmpDeeply(v.Num(), float64(0))
}