-
Notifications
You must be signed in to change notification settings - Fork 2
/
record_parser_test.go
96 lines (90 loc) · 1.78 KB
/
record_parser_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
package hpcmodel_test
import (
hpcmodel "github.com/cemc-oper/hpc-model-go"
"testing"
)
func TestBuildRecordParser_TokenRecordParser(t *testing.T) {
category := &hpcmodel.QueryCategory{
RecordParserClass: "TokenRecordParser",
RecordParserArguments: []string{"1", "|"},
}
_, err := hpcmodel.BuildRecordParser(category)
if err != nil {
t.Errorf("Build TokenRecordParser failed.")
}
}
func TestTokenRecordParser_Parse(t *testing.T) {
var tests = []struct {
index int
sep string
records []string
result string
}{
{
0,
"|",
[]string{"nwp_xp|(null)|1|0|NONE"},
"nwp_xp",
},
{
1,
"|",
[]string{"nwp_xp|(null)|1|0|NONE"},
"(null)",
},
{
2,
"|",
[]string{"nwp_xp|(null)|1|0|NONE"},
"1",
},
{
3,
"|",
[]string{"nwp_xp|(null)|1|0|NONE"},
"0",
},
}
for _, test := range tests {
p := &hpcmodel.TokenRecordParser{
Index: test.index,
Sep: test.sep,
}
result := p.Parse(test.records)
if result != test.result {
t.Errorf("result is error: %d, result is %s, expect is %s",
test.index, result, test.result)
}
}
}
func TestTokenRecordParser_SetArguments(t *testing.T) {
var tests = []struct {
arguments []string
index int
sep string
}{
{
[]string{"1", "|"},
1,
"|",
},
{
[]string{"2"},
2,
"",
},
}
for _, test := range tests {
parser := new(hpcmodel.TokenRecordParser)
err := parser.SetArguments(test.arguments)
if err != nil {
t.Errorf("set arguments %v failed: %v", test.arguments, err)
}
if parser.Index != test.index {
t.Errorf("set arguments %v Index is %d, requred %d", test.arguments, parser.Index, test.index)
}
if parser.Sep != test.sep {
t.Errorf("set arguments %v Sep is %s, requred %s", test.arguments, parser.Sep, test.sep)
}
}
}