forked from quickfixgo/quickfix
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcomponent_type_test.go
79 lines (70 loc) · 3.12 KB
/
component_type_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
package datadictionary_test
import (
"testing"
"github.com/quickfixgo/quickfix/datadictionary"
"github.com/stretchr/testify/assert"
)
func TestNewComponentType(t *testing.T) {
ft1 := datadictionary.NewFieldType("aname1", 11, "INT")
ft2 := datadictionary.NewFieldType("aname2", 12, "INT")
optionalField1 := datadictionary.NewFieldDef(ft1, false)
requiredField1 := datadictionary.NewFieldDef(ft1, true)
optionalField2 := datadictionary.NewFieldDef(ft2, false)
requiredField2 := datadictionary.NewFieldDef(ft2, true)
requiredComp1 := datadictionary.NewComponent(
datadictionary.NewComponentType("comp1", []datadictionary.MessagePart{requiredField1}),
true)
optionalComp1 := datadictionary.NewComponent(
datadictionary.NewComponentType("comp1", []datadictionary.MessagePart{requiredField1}),
false)
var tests = []struct {
testName string
parts []datadictionary.MessagePart
expectedFields []*datadictionary.FieldDef
expectedRequiredParts []datadictionary.MessagePart
expectedRequiredFields []*datadictionary.FieldDef
}{
{
testName: "test1",
parts: []datadictionary.MessagePart{optionalField1},
expectedFields: []*datadictionary.FieldDef{optionalField1},
},
{
testName: "test2",
parts: []datadictionary.MessagePart{requiredField1},
expectedFields: []*datadictionary.FieldDef{requiredField1},
expectedRequiredFields: []*datadictionary.FieldDef{requiredField1},
expectedRequiredParts: []datadictionary.MessagePart{requiredField1},
},
{
testName: "test3",
parts: []datadictionary.MessagePart{requiredField1, optionalField2},
expectedFields: []*datadictionary.FieldDef{requiredField1, optionalField2},
expectedRequiredFields: []*datadictionary.FieldDef{requiredField1},
expectedRequiredParts: []datadictionary.MessagePart{requiredField1},
},
{
testName: "test4",
parts: []datadictionary.MessagePart{requiredField2, optionalComp1},
expectedFields: []*datadictionary.FieldDef{requiredField2, requiredField1},
expectedRequiredFields: []*datadictionary.FieldDef{requiredField2},
expectedRequiredParts: []datadictionary.MessagePart{requiredField2},
},
{
testName: "test5",
parts: []datadictionary.MessagePart{requiredField2, requiredComp1},
expectedFields: []*datadictionary.FieldDef{requiredField2, requiredField1},
expectedRequiredFields: []*datadictionary.FieldDef{requiredField2, requiredField1},
expectedRequiredParts: []datadictionary.MessagePart{requiredField2, requiredComp1},
},
}
for _, test := range tests {
ct := datadictionary.NewComponentType("cname", test.parts)
assert.NotNil(t, ct, test.testName)
assert.Equal(t, "cname", ct.Name(), test.testName)
assert.Equal(t, test.expectedFields, ct.Fields(), test.testName)
assert.Equal(t, test.parts, ct.Parts(), test.testName)
assert.Equal(t, test.expectedRequiredFields, ct.RequiredFields(), test.testName)
assert.Equal(t, test.expectedRequiredParts, ct.RequiredParts(), test.testName)
}
}